A
A
alex995052019-01-28 00:38:36
PHP
alex99505, 2019-01-28 00:38:36

How to convert Soap to curl?

Hello, there is a soap request that I want to translate into curl, but the server responds with an error. There is no xml structure itself, there is only code:

$client = new SoapClient(null, array(
                'location' => 'https://site/soap.php',
                'uri' => 'https://site/soap.php',
                'login' => 'log', 'password' => 'pass')
        );
$parameters = array(
                "name1" =>"value1",
                "name2" => "value2");
$action='SOAPAction';
$results = $client->$action($parameters);

I tried like this, the result is an error about a bad request:
$xml=http_build_query($parameters);
$headers = array(
            "Cache-Control: no-cache",
            "Pragma: no-cache",
            "SOAPAction: $action",
            "Content-length: ".strlen($xml),
        ); 
$ch = curl_init();
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
        curl_setopt($ch, CURLOPT_URL, 'https://site/soap.php');
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_USERPWD, "log:pass"); /
        curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
        curl_setopt($ch, CURLOPT_TIMEOUT, 10);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $xml); /
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

        // converting
        $response = curl_exec($ch);
        curl_close($ch);

Any ideas what changes to make?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dimonchik, 2019-01-28
@dimonchik2013

nominally everything is correct
look for what is encoded in http_build_query, check httpbin what comes
send without parameters - or else how to get a successful response
if soap works as a client, but not with curl - use fidler for debugging

K
killerdr, 2019-02-19
@killerdr

and why is it necessary? If it’s just fundamental to remake the soap into a curl, then this is one thing, but if you get the data from the soap in the form of an array, and not an object, this is another.
from soap to curl like this:

$result = json_decode(json_encode($result) , true);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question