使用未命名参数将 Http post 发送到 asmx

发布于 2024-08-05 09:07:44 字数 542 浏览 1 评论 0原文

我有一个像这样的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不语却知心 2024-08-12 09:07:44

这更多的是 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..."

许久 2024-08-12 09:07:44

只是为了重述这个问题。我有一个类似的问题,第三方工具发布了 json 对象 {a:1, b:2, c:3}

我的 .net 代码看起来像

public bool AcceptPush(ABCObject ObjectName)

The 3rd party tool does not post {ObjectName:{a:1, b:2, c:3}} 如果这样做的话就不会有任何问题。

您可以将 .net 编码如下:

public bool AcceptPush(int a, int b, int c)

但实际上,这要丑陋得多,并且实际对象比这个简单的示例要复杂得多

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

public bool AcceptPush(ABCObject ObjectName)

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:

public bool AcceptPush(int a, int b, int c)

But in reality this is much uglier and the acutal object is much more complicated than this simple example

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文