REST error-The request contain entity body but no Content-Type header.The infered media type application/octet-stream is not support for this resource(REST 错误-请求包含实体主体但没有 Content-Type 标头.推断的媒体类型 application/octet-stream 不支持此资源) - IT屋-程序员软件开发技术分享
问题描述
我正在尝试发送 POST 请求.虽然通过 POSTMAN 发送一切顺利,然后我尝试通过 C# 代码发送:
I'm trying to send POST request. While sending via POSTMAN all goes well, then I try to send it by C# code:
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"
The request contains an entity body but no Content-Type header. The inferred media type 'application/octet-stream' is not supported for this resource
我该如何解决?
推荐答案
试写:
Content-Type: application/json; charset=UTF-8"
或添加到您的标题中:
Accept: application/json
这篇关于REST 错误-请求包含实体主体但没有 Content-Type 标头.推断的媒体类型 application/octet-stream 不支持此资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:REST 错误-请求包含实体主体但没有 Content-Type 标头.推断的媒体类型 application/octet-stream 不支持此资源


- C#MongoDB使用Builders查找派生对象 2022-09-04
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- 输入按键事件处理程序 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- 如何用自己压缩一个 IEnumerable 2022-01-01
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01