使用AddMvcCore进行webapi时发生415错误

问题描述:

使用AddMvc进行webapi调用时,一切正常,但在使用AddMvcCore时返回415。使用AddMvcCore进行webapi时发生415错误

请求首部设置为

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

任何思想?

原来我只需要添加一个多线

services.AddMvcCore() .AddJsonFormatters()

我认为这是因为Web API就像

public string Post([FromBody] JObject arg)

它需要json.net转换json字符串。

相关讨论是here

+2

你是男人!从一个空的web API项目开始,肯定有一些陷阱。 –