This morning I asked a few questions, referring to an external API that does not meet the HTTP specification for writing.
As part of my post, they want Content-Type and Content-Disposition , which cannot be added to the HttpClient object. To add these headers, you need to create an HttpRequestMessage . There you need to add headers to the Content property.
private HttpRequestMessage GetPostMessage(string uri, string contentType, string fileName, Stream content) { var request = new HttpRequestMessage { Content = new StreamContent(content), RequestUri = new Uri(uri), Method = HttpMethod.Post }; // contentType = "video/mp4" request.Content.Headers.ContentType = new MediaTypeHeaderValue(contentType); //Need TryAddWithoutValidation because of the equals sign in the value. request.Content .Headers .TryAddWithoutValidation("Content-Disposition", $"attachment; filename=\"{Path.GetFileName(fileName)}\""); // If there is no equals sign in your content disposition, this will work: // request.Content.Headers.ContentDisposition = // new ContentDispositionHeaderValue($"attachment; \"{Path.GetFileName(fileName)}\""); return request; }
krillgar Jul 11 '17 at 12:05 2017-07-11 12:05
source share