REST 错误 - 请求包含实体正文,但没有 Content-Type 标头。推断的媒体类型 application/octet-stream 不支持此资源

2024-03-31

我正在尝试发送 POST 请求。 通过 POSTMAN 发送一切顺利,然后我尝试通过 C# 代码发送它:

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;

var client = new RestClient(MY-URL);
var request = new RestRequest(Method.POST);
request.Credentials = new System.Net.NetworkCredential(ServerUsername, Password);
request.AddHeader("Cache-Control", "no-cache");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("undefined", My JSON Data, ParameterType.RequestBody);
IRestResponse response = client.Execute(request);

我收到此错误:

该请求包含实体主体,但不包含 Content-Type 标头。此资源不支持推断的媒体类型“application/octet-stream”

我该如何解决?


尝试写:

Content-Type: application/json; charset=UTF-8"

或者添加到您的标题中:

Accept: application/json
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

REST 错误 - 请求包含实体正文,但没有 Content-Type 标头。推断的媒体类型 application/octet-stream 不支持此资源 的相关文章

随机推荐