异常消息“:”没有 MediaTypeFormatter 可用于从“postman”中媒体类型为“multipart/form-data”的内容中读取类型为“user”的对象
-
22-12-2019 - |
题
我正在使用 Web API 创建登录服务。当我检查时 fiddler
它工作正常,但是当我检查时 postman
的 chrome
它显示错误:
{ "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 系统中检查这一点。
解决方案
单击“标题”按钮,输入标题和值
Content-Type: application/json
检查下面的链接以了解小提琴和邮递员都使用相同的内容类型在 POST 中将 json 发送到 Web API 服务时出错
其他提示
我遇到了相同的问题,但后来我发现我是在使用Ajax帖子来调用WebAPI,而是将其更改为“恢复”。但错误大多是误导性的。所以我一直关注媒体类型。
此资源不支持请求实体的媒体类型“text/plain”。",
$http({
method: 'POST',
将其更改为
$http({
method: '**GET**',
不隶属于 StackOverflow