예외 메시지“:""postman"의 미디어 유형이 'multipart/form-data인 콘텐츠에서 'user' 유형의 개체를 읽는 데 사용할 수 있는 MediaTypeFormatter가 없습니다.

StackOverflow https://stackoverflow.com//questions/24054590

문제

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을 웹 API 서비스로 보내는 중 오류가 발생했습니다.

다른 팁

나는 같은 문제에 빠졌지 만 나중에 나는 Ajax 게시물을 사용하여 Webapi에 전화를 걸고 있다는 것을 알아 차렸다.그러나 오류는 대부분 잘못된 것이었습니다.그래서 나는 항상 미디어 유형에 집중했습니다.

요청 엔터티의 미디어 유형 'text/plain'은 이 리소스에 지원되지 않습니다.",

$http({             
method: 'POST',

다음으로 변경하세요.

$http({             
method: '**GET**',
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top