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?
How to configure ASP.NET Core Web API to only accept `application/json`?
Asked Answered
Took me a while, but adding the consumes attribute (rather than produces) will do the trick for you.
[Consumes("application/json")]
Set [Produces("application/json")]
for controller which can achieve the effect you want.
[Produces("application/json")]
public class WeatherForecastController : ControllerBase
{
}
For more details, you can refer to this document.
The Op asked for content type of the request, not the response. –
Melodrama
Took me a while, but adding the consumes attribute (rather than produces) will do the trick for you.
[Consumes("application/json")]
© 2022 - 2024 — McMap. All rights reserved.