Accept Content-Type:text/json request in Minimal API

92 Views Asked by At

I am currently using .NET8 and Minimal API to handle requests. Everything works perfectly when a request has a header with the value Content-Type: application/json. However, when the 'Content-Type' is set to 'text/json', the API returns an HTTP code 415 error.

I am wondering how I can configure my Minimal API to accept requests with the 'Content-Type' set to 'text/json'?"

1

There are 1 best solutions below

0
MRP On

To resolve this issue we should use .Accepts(typeof(Something), "text/json") after .MapPost or .MapXXX method.