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?
Asked
Active
Viewed 1,798 times
2

tRuEsAtM
- 3,517
- 6
- 43
- 83
2 Answers
2
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.

Chen
- 4,499
- 1
- 2
- 9
-
1The Op asked for content type of the request, not the response. – Adam Hardy Feb 02 '23 at 23:12
1
Took me a while, but adding the consumes attribute (rather than produces) will do the trick for you.
[Consumes("application/json")]

Adam Hardy
- 377
- 3
- 9