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 不支持此资源
基础教程推荐
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01
- MS Visual Studio .NET 的替代品 2022-01-01
- c# Math.Sqrt 实现 2022-01-01
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30
- SSE 浮点算术是否可重现? 2022-01-01
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01
- 将 XML 转换为通用列表 2022-01-01
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- rabbitmq 的 REST API 2022-01-01
- 如何激活MC67中的红灯 2022-01-01