这让我发疯,我在任何地方都设置了 ContentType 标头,但似乎无法让它停止发送文本/纯文本。
在 Fiddler 中观察数据,请求总是在请求:
POST http://domain.com HTTP/1.1
内容类型:文本/纯文本;字符集=utf-8
using (var httpClient = new HttpClient())
{
var request = new HttpRequestMessage(HttpMethod.Post, "http://domain.com");
request.Content = new StringContent(Serialize(obj), Encoding.UTF8, "text/xml");
request.Content.Headers.Clear();
request.Content.Headers.ContentType = new MediaTypeHeaderValue("text/xml");
request.Headers.Clear();
request.Headers.Add("Content-Type","text/xml");
var response = await httpClient.SendAsync(request);
return await response.Content.ReadAsStringAsync();
}