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

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屋-程序员软件开发技术分享
本文介绍了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"

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 不支持此资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)