我正在尝试避免将我的请求从application / json转换为OPTION
的预检CORS
text/plain
请求。我的GET
请求工作正常。但是在调用POST
请求时。我收到了以下错误
“没有MediaTypeFormatter可用于从媒体类型为”text / plain“的内容中读取”XXX“类型的对象”
由于我现在将json作为普通对象传递,我想知道是否有可能在传递反序列化之前捕获Web服务上的POST数据并将其转换为JSON。
提琴手请求
POST
http://localhost:49531/api/Configuration/Edit
Accept: application/json, text/plain, */*
Origin: http://localhost:31775
Content-Type: text/plain
提琴手回复
HTTP/1.1 415 Unsupported Media Type
Content-Type: application/json; charset=utf-8
Expires: -1
Server: Microsoft-IIS/10.0
Access-Control-Allow-Origin: *
X-AspNet-Version: 4.0.30319
X-SourceFiles: =?UTF-8?B?RTpcVEZTXFJQTVNcU21hcnRcR2VuZXJhbFxTbWFydC5XZWIuV2ViQXBpXGFwaVxDb25maWd1cmF0aW9uXEVkaXQ=?=
X-Powered-By: ASP.NET
Date: Fri, 23 Jun 2017 13:45:36 GMT
Content-Length: 778
{
"$type": "System.Web.Http.HttpError, System.Web.Http",
"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 'XXX' 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)"
}