为 webapi 使用 AddMvcCore 时出现 415 错误

Get 415 error when using AddMvcCore for webapi

使用 AddMvc 进行 webapi 调用时一切正常,但使用 AddMvcCore 时会返回 415。

请求 header 设置为

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

有什么想法吗?

原来只需要加一行就可以了

services.AddMvcCore() .AddJsonFormatters()

我认为这是因为网络 API 就像

public string Post([FromBody] JObject arg)

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

相关讨论是here