【问题标题】:System.Net.Http.UnsupportedMediaTypeException exception occur in fiddler on running Web API post request in fiddler在提琴手中运行 Web API 发布请求时,提琴手中发生 System.Net.Http.UnsupportedMediaTypeException 异常
【发布时间】:2015-07-13 09:41:19
【问题描述】:

我是 ASP.NET MVC web api 的新手。我正在尝试运行由 Visual Studio 2013 创建的默认 web api 项目。另外,我正在使用 fiddler 来测试 web api。

在该默认项目中,创建了一个发布方法“api/Account/Register”。当我尝试在提琴手中运行它时,会发生 UnsupportedMediaTypeException。我搜索了很多并尝试添加内容类型 content-type: application/json;提琴手的作曲家部分的标题。但异常仍然发生。以下是完整的异常细节 -

{"Message":"请求包含实体主体,但没有 Content-Type 标头。此资源不支持推断的媒体类型 'application/octet-stream'。","ExceptionMessage":"没有 MediaTypeFormatter可用于从媒体类型为“application/octet-stream”的内容中读取“RegisterBindingModel”类型的对象。","ExceptionType":"System.Net.Http.UnsupportedMediaTypeException","StackTrace":" at System.Net.Http .HttpContentExtensions.ReadAsAsync[T](HttpContent content, Type type, IEnumerable1 formatters, IFormatterLogger formatterLogger, CancellationToken cancellationToken)\r\n at System.Net.Http.HttpContentExtensions.ReadAsAsync(HttpContent content, Type type, IEnumerable1 formatters, IFormatterLogger formatterLogger, CancellationToken cancelToken)\r\n at System.Web.Http.ModelBinding.FormatterParameterBinding.ReadContentAsync(HttpRequestMessage request, Type type, IEnumerable`1 formatters, IFormatterLogger formatterLogger, CancellationToken cancelToken)"}

这是我在提琴手中的设置 -

请让我知道我缺少什么。

【问题讨论】:

    标签: asp.net-mvc post asp.net-web-api fiddler


    【解决方案1】:

    尝试插入一个接受头:

    Accept: */*
    

    含义:给予你所拥有的......

    或者

    Accept: application/json
    

    意思:给我JSON

    【讨论】:

    • 尝试添加接受头...没有变化,问题仍然存在
    • 其实你的Content-Type header好像有问题。
    • 尝试替换大小写(“Content-Type: application/json”)并去掉末尾的分号...
    • 很高兴为您提供帮助:)
    • 提琴手很棒。但我个人使用 getpostman.com 进行所有 API 测试
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多