asp.net-core-webapi.net-6.0http-accept-header

How to configure ASP.NET Core Web API to only accept `application/json`?


I would like to configure my ASP.NET Core Web API using .NET 6 to only accept application/json as the accept header value. How can I configure that?


Solution

  • Took me a while, but adding the consumes attribute (rather than produces) will do the trick for you.

    [Consumes("application/json")]