0

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"));
});

すべて正常に動作します。しかし、デフォルトの Json-Serializer の代わりに Newtonsoft.Json を使用したいので、コードを次のように変更しました

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"));
});

しかし、コントローラに a が送信されるたびapplication/csp-reportに、415 ステータス コードが返されます。

4

1 に答える 1