【问题标题】:ExceptionMessage": "No MediaTypeFormatter is available to read an object of type 'user' from content with media type 'multipart/form-data in "postman"ExceptionMessage”:“没有 MediaTypeFormatter 可用于从“邮递员”中媒体类型为“multipart/form-data”的内容中读取“用户”类型的对象
【发布时间】:2014-07-26 02:46:57
【问题描述】:

我正在使用 Web API 创建登录服务。当我检查 fiddler 时,它工作正常,但是当我检查 postmanchrome 时,它显示错误:

{    "Message": "An error has occurred.",
    "ExceptionMessage": "No MediaTypeFormatter is available to read an object of type 'user' from content with media type 'multipart/form-data'.",
    "ExceptionType": "System.InvalidOperationException",
    "StackTrace": "   
    at System.Net.Http.HttpContentExtensions.ReadAsAsync[T](HttpContent content, Type type, IEnumerable`1 formatters, IFormatterLogger formatterLogger)\r\n
    at System.Net.Http.HttpContentExtensions.ReadAsAsync(HttpContent content, Type type, IEnumerable`1 formatters, IFormatterLogger formatterLogger)\r\n
    at System.Web.Http.ModelBinding.FormatterParameterBinding.ReadContentAsync(HttpRequestMessage request, Type type, IEnumerable`1 formatters, IFormatterLogger formatterLogger)\r\n
    at System.Web.Http.ModelBinding.FormatterParameterBinding.ExecuteBindingAsync(ModelMetadataProvider metadataProvider, HttpActionContext actionContext, CancellationToken cancellationToken)\r\n
    at System.Web.Http.Controllers.HttpActionBinding.<>c__DisplayClass1.<ExecuteBindingAsync>b__0(HttpParameterBinding parameterBinder)\r\n
    at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()\r\n
    at System.Threading.Tasks.TaskHelpers.IterateImpl(IEnumerator`1 enumerator, CancellationToken cancellationToken)" 
}

public class user
{
    //public user(string userId, string password)
    //{
    //    UserId = userId;
    //    Password = password;
    //}

    public string UserId { get; set; }
    public string Password { get; set; }
}

我正在检查postman,如果此服务能够在移动应用程序中访问。另外,在mac系统中检查这个。

【问题讨论】:

    标签: asp.net-web-api fiddler postman


    【解决方案1】:

    点击标题按钮,输入标题和值

    Content-Type: application/json
    

    检查下面的链接,小提琴和邮递员都使用相同的内容类型 Error sending json in POST to web API service

    【讨论】:

    • 我尝试使用 Chrome Navigator 的 POSTMAN 并使用此标头值正常工作。谢谢!
    【解决方案2】:

    我遇到了同样的问题,但后来我发现我正在调用 WebAPI 使用 ajax POST 而不是我将其更改为 GET 并且它有效。但错误主要是误导。所以我一直专注于媒体类型。

    此资源不支持请求实体的媒体类型“text/plain”。",

    $http({             
    method: 'POST',
    

    改成

    $http({             
    method: '**GET**',
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-05-29
      • 2012-09-12
      • 2016-06-29
      • 1970-01-01
      • 1970-01-01
      • 2018-07-03
      • 1970-01-01
      • 2017-08-05
      相关资源
      最近更新 更多