【发布时间】:2018-08-27 10:50:08
【问题描述】:
我的 ASP.NET Web API 中有一个 POST 方法,该方法将被无法发送 Content-Type 标头的客户端使用。
我想检查请求的Content-Type 标头,如果它为空,我想将其设置为application/x-www-form-urlencode。
我如何做到这一点?
附:如果请求没有Content-Type: application/x-www-form-urlencode,我得到:
请求包含实体主体,但没有 内容类型标头。推断的媒体类型 不支持“应用程序/八位字节流” resource.No MediaTypeFormatter 是 可用于从内容中读取“CustomerModel”类型的对象 媒体类型 '应用程序/八位字节流'.System.Net.Http.UnsupportedMediaTypeException 在 System.Net.Http.HttpContentExtensions.ReadAsAsync[T](HttpContent 内容,类型类型,IEnumerable
1 formatters, IFormatterLogger formatterLogger, CancellationToken cancellationToken) at System.Net.Http.HttpContentExtensions.ReadAsAsync(HttpContent content, Type type, IEnumerable1 格式化程序,IFormatterLogger 格式化程序记录器, CancellationToken 取消令牌)在 System.Web.Http.ModelBinding.FormatterParameterBinding.ReadContentAsync(HttpRequestMessage 请求,类型类型,IEnumerable`1 格式化程序,IFormatterLogger 格式化程序记录器,CancellationToken 取消令牌)
【问题讨论】:
-
你的代码在哪里!你都尝试了些什么?请参阅How to Ask 页面以获得澄清此问题的帮助。
-
问题解决了吗?
标签: asp.net-web-api content-type