No MediaTypeFormatter is available to read an object of type 'Advertisement' in asp.net web api

前端 未结 3 953
悲哀的现实
悲哀的现实 2021-02-18 18:13

I have a class that name is Advertisement:

 public class Advertisement
{
    public string Title { get; set; }
    public string Desc { get; set; }
}
         


        
3条回答
  •  被撕碎了的回忆
    2021-02-18 18:18

    "ExceptionMessage": "No MediaTypeFormatter is available to read an object of type 'Advertisement' from content with media type 'application/octet-stream'.",

    That means that your application cannot read octet-stream Content-Type - which is what the request provided. This is one frustration I have with Web API. However there is a way around it. The easy way is to modify the Content-type to 'application/json' or 'application/xml' which is easily read. The harder way is to provide your own MediaTypeFormatter.

提交回复
热议问题