错误:值'application / json的格式; charset = utf-8'无效。来自webapi

时间:2017-11-16 15:42:11

标签: c# asp.net json asp.net-web-api utf-8

我在我的mvc项目中使用webapi,当我从浏览器向api调用发出请求时,我收到以下错误:

我正在使用.netFramework 4.0

异常详细信息:

应用程序中的服务器错误。

值'application / json的格式; charset = utf-8'无效。

说明

  An unhandled exception occurred during the execution of the current web 
  request. Please review the stack trace for more information about the 
  error and where it originated in the code. 

异常详细信息:

  System.FormatException: The format of value 'application/json; 
  charset=utf-8' is invalid.

来源错误:

  An unhandled exception was generated during the execution of the current 
  web request. Information regarding the origin and location of the 
  exception can be identified using the exception stack trace below.

堆栈追踪:

        [FormatException: The format of value 'application/json; charset=utf-8' 
        is invalid.]
        System.Net.Http.Headers.MediaTypeHeaderValue.CheckMediaTypeFormat(String 
        mediaType, String parameterName) +119919
        System.Net.Http.Headers.MediaTypeHeaderValue..ctor(String mediaType) +23
        System.Net.Http.ObjectContent.BuildHeaderValue(String mediaType) +63
        System.Net.Http.ObjectContent`1..ctor(T value, MediaTypeFormatter 
        formatter, String mediaType) +66
        System.Net.Http.HttpRequestMessageExtensions.CreateResponse(HttpRequestMessage request, HttpStatusCode statusCode, T value, HttpConfiguration configuration) +892
        System.Net.Http.HttpRequestMessageExtensions.CreateResponse(HttpRequestMessage request, HttpStatusCode statusCode, T value) +104
        System.Web.Http.Dispatcher.HttpControllerDispatcher.HandleException(HttpRequestMessage request, Exception exception, HttpConfiguration configuration) +191
        System.Web.Http.Dispatcher.HttpControllerDispatcher.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) +284
        System.Net.Http.DelegatingHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) +41
        System.Web.Http.HttpServer.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) +347
        System.Net.Http.HttpMessageInvoker.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) +55
        System.Web.Http.WebHost.HttpControllerHandler.BeginProcessRequest(HttpContextBase httpContextBase, AsyncCallback callback, Object state) +316
        System.Web.Http.WebHost.HttpControllerHandler.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext httpContext, AsyncCallback callback, Object state) +77
        System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +103
        System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155

我在谷歌搜索但找不到合适的解决方案。

0 个答案:

没有答案