Using System.Net.Http.Httpclient, I am trying to do a multipart post in C# and with a wp8.
This is a snippet of my code:
varclient = new HttpClient();
client.DefaultRequestHeaders.TryAddWithoutValidation(
"Content-Type", "application/json");
content = new MultipartFormDataContent();
content.Add(new StringContent(requestObj, Encoding.UTF8, "application/json"), "request");
but using Fiddler, I noticed that I am sending this:
Content-Disposition: form-data; name=request
Content-Type: text/plain; charset=utf-8
while I need to send this (taken from an android device where the call is working):
Content-Disposition: application/json; name="request"
Content-Type: text/plain; charset=UTF-8
- How to achieve the expected result?
Best Answer
What about:
setting the header on the HttpContent using TryAddWithoutValidation
and changing the MultipartFormDataContent into a MultipartContent object:
This results in these headers