本文介绍了REST 错误-请求包含实体主体但没有 Content-Type 标头.推断的媒体类型 application/octet-stream 不支持此资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试发送 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"

我该如何解决?

推荐答案

试写:

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

或添加到您的标题中:

Accept: application/json

这篇关于REST 错误-请求包含实体主体但没有 Content-Type 标头.推断的媒体类型 application/octet-stream 不支持此资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 22:24