【问题标题】:The request entity's media type 'application/x-www-form-urlencoded' is not supported for this resource此资源不支持请求实体的媒体类型“application/x-www-form-urlencoded”
【发布时间】:2016-10-03 06:05:12
【问题描述】:

我正在使用 ASPNET Boilerplate 框架来开发我的应用程序,但我确信这是一个特定于 WebAPI 的问题。我正在使用基于以下应用层函数的动态 WebAPI 函数。

Application Service function

在我的 Angular 应用程序中,我使用以下代码将数据发布到动态 API 并最终发布到应用层函数。

var formDataObject = new FormData();
                formDataObject.append('avatar', vm.group.avatar);
                formDataObject.append('name', vm.group.name);
                formDataObject.append('description', vm.group.description);
                
                $.ajax({
                    url: abp.appPath + 'api/services/app/group/CreateGroup',
                    processData: false,
                    //contentType: false,
                    type: 'POST',
                    data: formDataObject
                });

我在 Chrome 控制台中收到以下错误:

{"message":"The request entity's media type 'application/x-www-form-urlencoded' is not supported for this resource.","exceptionMessage":"No MediaTypeFormatter is available to read an object of type 'InputGroup' from content with media type 'application/x-www-form-urlencoded'.","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.Net.Http.HttpContentExtensions.ReadAsAsync(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)"}

我尝试了以下解决方案,但均未成功:

  • 使用 FormDataCollection 作为参数类型。
  • 没有文件(头像)对象的帖子。失败。
  • 使用 application/formdata 类型发布。失败。

我在互联网上看到的所有解决方案都不适合我。

【问题讨论】:

    标签: angularjs asp.net-mvc asp.net-web-api data-formatters aspnetboilerplate


    【解决方案1】:

    好的,经过数小时的调试,我解决了这个问题,所以如果其他人遇到同样的问题,可以节省时间。这不是 WebAPI 问题。 WebAPI 为 'application/x-www-form-urlencoded' 提供 MediaTypeFormatters。此问题是由于 Abp.WebApi 包的某些实现已过时所致。将您的 aspnet 样板包更新到 2016 年 9 月 28 日发布的 Abp v1.0。修复损坏的代码。并重新编译。这个问题应该得到解决。如果您仍有问题,请联系我,也许我可以提供帮助。

    【讨论】:

      猜你喜欢
      • 2020-02-02
      • 2017-07-16
      • 2021-02-25
      • 1970-01-01
      • 1970-01-01
      • 2013-03-24
      • 2021-06-19
      • 2020-12-27
      • 1970-01-01
      相关资源
      最近更新 更多