Asmx 请求 - 如何获取所有 POSTed 参数
有没有办法获取在 ASP.NET 中发布到 ASMX 的所有参数。 Request.Form/QueryString/Params - 全部不包含提交到页面的键。
is there a way to get all params that were posted to ASMX in ASP.NET . Request.Form/QueryString/Params - all do not contain keys that were submitted to the page.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
除非您的 ASMX 以内容类型为“
application/x-www-form-urlencoded
”的 HTTP POST 方式进行调用,否则您将无法从HttpRequest
对象获取这些参数。这只是因为请求正文可以是任何内容类型 - 例如,在脚本服务 (ASP.NET AJAX) 中,请求正文将包含 JSON 数据。如果 ASMX 已作为 SOAP Web 服务访问,则请求正文将是 xml(实际的 SOAP 信封)。
通常,ASP.NET 运行时会根据配置尝试解析请求正文,并尝试将其转换为方法调用以及实际的方法参数。所以正确的方法是检查方法代码中的方法参数。一种复杂的方法是引用请求内容类型并相应地解析(由您自己)请求正文 (
HttpRequest.InputStream
)。Unless your ASMX gets invokes as HTTP POST with content type as "
application/x-www-form-urlencoded
", you will not get those parameters fromHttpRequest
object.This is simply because request body can be of any content type - for example, in script services (ASP.NET AJAX), the request body will have JSON data. If ASMX has been accessed as a SOAP web service then the request body will be an xml (the actual SOAP envelope).
Typically, ASP.NET run-time based on the configuration, attempts to parse the request body and tries to convert it into an method call along with actual method parameters. So the correct way would be to check your method parameters in the method code. A convoluted approach would be to refer request content type and parse (by your self) the request body (
HttpRequest.InputStream
) accordingly.