ExceptionMessage ":" "Postman"のメディアタイプ 'マルチパート/フォームデータを使用してコンテンツから'ユーザー 'タイプのオブジェクトを読み取るためにMediaTypeFormatterが使用可能です。

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

質問

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システムで確認するには。

役に立ちましたか?

解決

ヘッダボタンをクリックすると、このheaderとvalue

の両方を入力します。
Content-Type: application/json
.

フィドルとポストマンのためのリンク以下のチェックどちらも同じコンテンツタイプを使用します POSTのJSON送信エラーWeb APIサービス

他のヒント

私は同じ問題に遭遇しますが、後で私は私がWebAPIを呼んでいたことを考え出しました 代わりにAjax POSTを使用して、それを取得し、それを処理しました。しかし誤差はほとんど誤解されていました。だから私がメディアの種類に焦点を当てていたすべての時間。

要求エンティティのメディアタイプ 'テキスト/プレーン'はこのリソースではサポートされていません。 "、

$http({             
method: 'POST',
.

に変更する
$http({             
method: '**GET**',
.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top