Answer the question
In order to leave comments, you need to log in
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);
$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);
Answer the question
In order to leave comments, you need to log in
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
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 questionAsk a Question
731 491 924 answers to any question