我有一个Web服务,人们可以在其中发布带有标头的请求,但是其中一个标有content-type = application / hal + json。我收到此消息错误:
状态:415不支持的媒体类型
{“ Message”:“ 此资源不支持请求实体的媒体类型'application / hal + json'。”“ ExceptionMessage”:“没有MediaTypeFormatter可用于从媒体类型为'application / hal + json'的内容中读取'LinksBody'类型的对象。”,“ ExceptionType”:“ System.Net.Http.UnsupportedMediaTypeException”,“ StackTrace”:“位于System.Net.Http.HttpContentExtensions.ReadAsAsync [T](HttpContent内容,类型,IEnumerable1 formatters, IFormatterLogger formatterLogger, CancellationToken cancellationToken)\r\n at System.Web.Http.ModelBinding.FormatterParameterBinding.ReadContentAsync(HttpRequestMessage request, Type type, IEnumerable
1格式器,IFormatterLogger formatterLogger,CancellationToken cancelledToken)”}
[当我尝试使用POSTMAN进行POST请求但使用content-type = application / json时,它的工作。
所以我的问题是,是否可以更改其他人的POST请求的标头?从application / hal + json到application / json。
我正在使用HttpResponseMessage Post。
谢谢。
这不是您问题的答案。但是我仍然想警告您,修改客户端请求标头不是一个好习惯。迟早您会遇到这种方法的麻烦。
正确的是在客户端发送正确的头。