使用未命名参数将 Http post 发送到 asmx
我有一个像这样的 webmethod:
[WebMethod]
public string HelloWorld(string a)
{
return a;
}
发布到我的 asmx webmethod 的说明说要像这样发布:
POST /Service1.asmx/HelloWorld HTTP/1.1
Host: localhost
Content-Type: application/x-www-form-urlencoded
Content-Length: length
a=string
但是我希望能够接受这一点:
POST /Service1.asmx/HelloWorld HTTP/1.1
Host: localhost
Content-Type: application/x-www-form-urlencoded
Content-Length: length
string
我该怎么做? 谢谢
I have a webmethod like this:
[WebMethod]
public string HelloWorld(string a)
{
return a;
}
The instructions to post to my asmx webmethod say to post like this:
POST /Service1.asmx/HelloWorld HTTP/1.1
Host: localhost
Content-Type: application/x-www-form-urlencoded
Content-Length: length
a=string
However I want to be able to accept this:
POST /Service1.asmx/HelloWorld HTTP/1.1
Host: localhost
Content-Type: application/x-www-form-urlencoded
Content-Length: length
string
How can I do that?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这更多的是 HTTP POST 协议的问题,而不是 ASP.NET 的问题。 POST 正文的格式必须为“variable=value;variable2=value2...”
This is more an issue of the HTTP POST protocol moreso than an ASP.NET issue. The format of the POST body must be "variable=value;variable2=value2..."
只是为了重述这个问题。我有一个类似的问题,第三方工具发布了 json 对象
{a:1, b:2, c:3}
我的 .net 代码看起来像
The 3rd party tool does not post
{ObjectName:{a:1, b:2, c:3}}
如果这样做的话就不会有任何问题。您可以将 .net 编码如下:
但实际上,这要丑陋得多,并且实际对象比这个简单的示例要复杂得多
Just to restate this problem. I have a similar issue where a 3rd party tool posts a json object
{a:1, b:2, c:3}
my .net code looks like
The 3rd party tool does not post
{ObjectName:{a:1, b:2, c:3}}
if it did there would not be any problem.You could code the .net as this:
But in reality this is much uglier and the acutal object is much more complicated than this simple example