WebAPI HelpPage出现Failed to generate the sample for media type 'application/x-www-form-urlencoded'. 错
来源:互联网 发布:oracle调用java http 编辑:程序博客网 时间:2024/06/05 17:02
WebApi参数页面的示例里,出现如下错误:
Failed to generate the sample for media type 'application/x-www-form-urlencoded'. Cannot use formatter 'JQueryMvcFormUrlEncodedFormatter' to write type 'Vehicle'.
调试查了一下原因,是因为WebAPI的Formatter里,存在一个类型为System.Web.Http.ModelBinding.JQueryMvcFormUrlEncodedFormatter的Formatter,而HelpPage又没有对进行对应的解析导致的。本来想改HelpPage代码,但想想其实不需要,只要把这个Formattter在WebAPI里移除就可以了,如下:
在App_Start的WebApiConfig.cs的Register方法里,加下如下这句将其移除:
config.Formatters.Remove(config.Formatters.FirstOrDefault(p => p.GetType() == typeof(System.Web.Http.ModelBinding.JQueryMvcFormUrlEncodedFormatter)));
如果你只要JSON格式,其它不要,可以这样写:
config.Formatters.Clear();config.Formatters.Add(new System.Net.Http.Formatting.JsonMediaTypeFormatter());
这句的意思是先将Formatter全部清除,再添加你想要的Formatter,这里用了Json,如果要XML,则
config.Formatters.Add(new System.Net.Http.Formatting.XmlMediaTypeFormatter());
参考:
https://stackoverflow.com/questions/18249344/exclude-media-type-sample-from-web-api-help-page
阅读全文
0 0
- WebAPI HelpPage出现Failed to generate the sample for media type 'application/x-www-form-urlencoded'. 错
- Content-Type: application/x-www-form-urlencoded
- application/x-www-form-urlencoded
- application/x-www-form-urlencoded
- application/x-www-form-urlencoded
- application/x-www-form-urlencoded
- application/x-www-form-urlencoded
- application/x-www-form-urlencoded
- application/x-www-form-urlencoded
- application/x-www-form-urlencoded
- application/x-www-form-urlencoded
- application/x-www-form-urlencoded
- application/x-www-form-urlencoded
- [转]Content-Type: application/x-www-form-urlencoded
- Content-Type: application/x-www-form-urlencoded什么意思
- 关于 Content-Type:application/x-www-form-urlencoded
- Spring MVC报错"Content type 'application/x-www-form-urlencoded' not supported"怎么解决
- Form元素application/x-www-form-urlencoded
- IOS开发中利用AudioToolbox播放系统声音
- playframework在intelij idea中的debug调试方法
- 如何通过adb 获取应用的版本号
- 22、Selenium + Python 实现 UI 自动化测试-操作日期时间控件
- 解决arcgis desktop 添加 arcgis server 提示无法连接问题
- WebAPI HelpPage出现Failed to generate the sample for media type 'application/x-www-form-urlencoded'. 错
- github上实用、常用的插件和库
- 虚拟机Linux(Centos)上用户密码忘记了怎么办?
- “数据高铁”的时代或将来临,要关注人工智能发展的多层次性,推进智能经济发展 | 大咖周语录
- unity学习
- 【LeetCode算法练习(C++)】Merge Two Sorted Lists
- 安装两个python使用
- 金融科技&大数据产品推荐:云途腾保险金融混合云——金融科技的云基石
- 装饰器设计模式