gpt4 book ai didi

c# - 强制HttpClient使用Content-Type : text/xml

转载 作者:行者123 更新时间:2023-12-03 13:46:15 25 4
gpt4 key购买 nike

这让我发疯了,我在所有可能且无法使它停止发送文本/纯文本的地方设置ContentType header 。

在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();
}

最佳答案

看来您尝试了:)这应该可以工作。

using (var httpClient = new HttpClient())
{
var request = new HttpRequestMessage(HttpMethod.Post, "http://domain.com");
request.Content = new StringContent(Serialize(obj), Encoding.UTF8, "text/xml");
var response = await httpClient.SendAsync(request);
return await response.Content.ReadAsStringAsync();
}

关于c# - 强制HttpClient使用Content-Type : text/xml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16973524/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com