我想MvcOptions
在 .Net 5 的输入格式化程序中添加一个新的 MediaType
当我执行以下操作时
services.AddControllers();
services.Configure<Microsoft.AspNetCore.Mvc.MvcOptions>(options =>
{
options.InputFormatters
.OfType<Microsoft.AspNetCore.Mvc.Formatters.SystemTextJsonInputFormatter>()
.First()
.SupportedMediaTypes
.Add(new Microsoft.Net.Http.Headers.MediaTypeHeaderValue("application/csp-report"));
});
一切正常。但我想使用 Newtonsoft.Json 而不是默认的 Json-Serializer 所以我将代码更改为
services.AddControllers()
.AddNewtonsoftJson();
services.Configure<Microsoft.AspNetCore.Mvc.MvcOptions>(options =>
{
options.InputFormatters
.OfType<Microsoft.AspNetCore.Mvc.Formatters.NewtonsoftJsonInputFormatter>()
.First()
.SupportedMediaTypes
.Add(new Microsoft.Net.Http.Headers.MediaTypeHeaderValue("application/csp-report"));
});
但是现在每次将 aapplication/csp-report
发送到控制器时,我都会收到 415 状态码。