简体   繁体   中英

Execute curl using php

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.

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.

Try removing this line:

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

Then post what the output is.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM