Search code examples
asp.net-web-apiasp.net-corecontent-type

Get 415 error when using AddMvcCore for webapi


Everything works fine when using AddMvc for webapi call, but it throws 415 back when using AddMvcCore.

request header is set as

Content-Type: application/json; charset=UTF-8 Accept: application/json

Any thought ?


Solution

  • It turns out I just need to add one more line

    services.AddMvcCore() .AddJsonFormatters()

    I think it is because the Web API was like

    public string Post([FromBody] JObject arg)

    It requires json.net to convert the json string.

    Related discussion is here