我们将媒体类型限制为'application/json'。所以如果请求头部包含'Content-Type:text/plain',它会回应下面的错误消息和状态码415.这种行为是预期的,但我想发送状态码为415的空响应。我们如何做到这一点。 Net Web API?如何自定义415状态码的错误消息?
{
"message": "The request entity's media type 'text/plain' is not supported for this resource.",
"exceptionMessage": "No MediaTypeFormatter is available to read an object of type 'MyModel' from content with media type 'text/plain'.",
"exceptionType": "System.Net.Http.UnsupportedMediaTypeException",
"stackTrace": " at System.Net.Http.HttpContentExtensions.ReadAsAsync[T](HttpContent content, Type type, IEnumerable`1 formatters, IFormatterLogger formatterLogger, CancellationToken cancellationToken)\r\n at System.Web.Http.ModelBinding.FormatterParameterBinding.ReadContentAsync(HttpRequestMessage request, Type type, IEnumerable`1 formatters, IFormatterLogger formatterLogger, CancellationToken cancellationToken)"
}