未能生成媒体类型“应用程序/ x-WWW的形式urlen codeD”样本 [英] Failed to generate the sample for media type 'application/x-www-form-urlencoded'

查看:151
本文介绍了未能生成媒体类型“应用程序/ x-WWW的形式urlen codeD”样本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近,我开始创建一个ASP.net的Web API

I recently started creating a ASP.net Web API

有关某种原因,我不断收到查看自动生成的帮助文档,当这个错误:

For some reason I keep receiving this error when viewing the auto generated help documentation:

这是一个POST方法

样品展示了应用程序/ JSON和应用精细/ XML

Samples show up fine for application/json and application/xml

我不太清楚,但应用程序/ -X-WWW的形式urlen codeD不断显示出来。

I'm not quite sure but the application/-x-www-form-urlencoded keeps showing up

我GOOGLE了错误相当多,但不能完全找不到什么可能导致这种

I've googled the error quite a bit but can't quite find what might be causing this

我真的AP preciate可以提供任何帮助,也请让我知道如果你有任何问题。

I truly appreciate any help that can be provided, also please let me know if you have any questions.

推荐答案

这是一个预期的行为。 HelpPage样本生成使用实际的格式化present在HttpConfiguration'写'样本对象。 FormUrlEn codedMediaTypeFormatter不能写任何类型的,因此HelpPage不能生成样品了。
作为一种变通方法,你可以明确地提供样本为特定类型(如区域所示\\ HelpPage \\ App_Start \\ HelpPageConfig.cs的评论code)。

This is an expected behavior. HelpPage sample generation uses the actual formatters present on the HttpConfiguration to 'write' the sample objects. FormUrlEncodedMediaTypeFormatter cannot 'write' any type, hence HelpPage cannot generate samples for it. As a workaround you could explicitly supply a sample for a particular type (as shown in the Areas\HelpPage\App_Start\HelpPageConfig.cs's commented code).

config.SetSampleForType("[0]=foo&[1]=bar", new MediaTypeHeaderValue("application/x-www-form-urlencoded"), typeof(IEnumerable<string>));

这篇关于未能生成媒体类型“应用程序/ x-WWW的形式urlen codeD”样本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆