【发布时间】:2017-04-06 14:21:42
【问题描述】:
我们已将媒体类型限制为“应用程序/json”。因此,如果请求标头包含“Content-Type:text/plain”,它会响应以下错误消息和状态代码 415。这种行为是预期的,但我想发送带有状态代码 415 的空响应。我们如何在 .网络网络 API?
{
"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)"
}
【问题讨论】:
标签: c# asp.net-web-api2