使用php执行curl

发布于 2024-12-25 15:57:49 字数 1046 浏览 1 评论 0原文

我可以像这样使用java调用soap服务器

        Call call = new Call();
        URL url = new URL("http://soap-something.dash.com/servlet/rpcrouter");
        call.setTargetObjectURI("urn:login-transport");
        call.setMethodName("confirmPassword");
        call.setParams(a vector);
        resp = call.invoke(url, "");

但我的问题是如何使用curl和php调用相同的函数,我已经尝试过这个,但它可能是某种有趣的代码

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "http://soap-something.dash.com/servlet/rpcrouter?urn:login-transport");
    curl_setopt($ch, CURLOPT_HEADER, true);
    curl_setopt($ch, CURLOPT_HEADERFUNCTION, "confirmPassword");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($ch, CURLOPT_POSTFIELDS, array("username"=>"pritom", "password"=>"pritom"));
    $head = curl_exec($ch);
    $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    curl_close($ch);
    echo "<br/>HTTP CODE: " . $httpCode;
    print_r($head);

但它回显http代码100,我这样做未从肥皂服务器找到任何结果。但我的soap服务器没问题,通过java测试。

I can call a soap server using java like this

        Call call = new Call();
        URL url = new URL("http://soap-something.dash.com/servlet/rpcrouter");
        call.setTargetObjectURI("urn:login-transport");
        call.setMethodName("confirmPassword");
        call.setParams(a vector);
        resp = call.invoke(url, "");

But my question is how can I call this same function using curl and php, I have already tried this, but it may be some kind of funny code

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "http://soap-something.dash.com/servlet/rpcrouter?urn:login-transport");
    curl_setopt($ch, CURLOPT_HEADER, true);
    curl_setopt($ch, CURLOPT_HEADERFUNCTION, "confirmPassword");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($ch, CURLOPT_POSTFIELDS, array("username"=>"pritom", "password"=>"pritom"));
    $head = curl_exec($ch);
    $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    curl_close($ch);
    echo "<br/>HTTP CODE: " . $httpCode;
    print_r($head);

But it echo http code 100 and I do not found any result from soap server. But my soap server is ok, tested by java.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

寄居人 2025-01-01 15:57:49

对我来说看起来不错,除了 CURLOPT_HEADER 需要为 true 或 false(是否在输出中包含 HTTP 标头),

curl_setopt($ch, CURLOPT_HEADER, "confirmPassword");

应该是

curl_setopt($ch, CURLOPT_HEADER, true);

我只能猜测确认密码是什么,如果它是回调,则应该使用 CURLOPT_HEADERFUNCTION 代替。

但正如 Ariel 指出的,你没有告诉我们问题是什么。

Looks fine to me, except CURLOPT_HEADER needs to be either true or false (include HTTP header in output or not),

curl_setopt($ch, CURLOPT_HEADER, "confirmPassword");

should be

curl_setopt($ch, CURLOPT_HEADER, true);

I can only guess what confirmPassword is, if it's a callback, you should use CURLOPT_HEADERFUNCTION instead.

But as Ariel pointed out, you're not telling us what the problem is.

ㄖ落Θ余辉 2025-01-01 15:57:49

尝试删除这一行:

curl_setopt($ch, CURLOPT_NOBODY, false); // remove body

然后发布输出是什么。

Try removing this line:

curl_setopt($ch, CURLOPT_NOBODY, false); // remove body

Then post what the output is.

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