2014-06-05 23 views
5

我正在使用Web API創建登錄服務。當我與fiddler檢查它的正常工作,但是當我用chromepostman檢查它的示值誤差:ExceptionMessage「:」沒有MediaTypeFormatter可用於從「郵遞員」中的媒體類型爲「multipart/form-data」的內容中讀取類型爲'user'的對象

{ "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系統中檢查。

回答

10

點擊頁眉按鈕輸入這個報頭和值

Content-Type: application/json 

檢查下面鏈接,小提琴和郵遞員都使用相同的內容類型 Error sending json in POST to web API service

+0

我嘗試在Chrome Navigator和作品的郵差用這個標題值罰款,謝謝! – mggSoft

0

我遇到同樣的問題,但後來我想通它出來,我打電話給WebAPI 使用ajax POST,而我改變它爲GET,它的工作。但錯誤主要是誤導。所以我一直專注於媒體類型。

請求實體的媒體類型 'text/plain的' 不支持這個資源。「

$http({    
method: 'POST', 

將其更改爲

$http({    
method: '**GET**', 
相關問題