I would like someone with experience in SOAP requests with Curl and PHP to assist me. I have the situation where I am making SOAP PHP requests from my PHP app to remote server which is working great from my local server (PHP 7.0 , Curl 7.47 ) The problem is when I deploy the app on my server with PHP 5.5.9 and curl 7.50 , with completely same code, I get empty response from the Curl call. Here is the part of the code:
$xml_post_string = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tcit="urn:microsoft-dynamics-schemas/page/tcitems">';
$xml_post_string .= '<soapenv:Header/>';
$xml_post_string .= '<soapenv:Body>';
$xml_post_string .= '<tcit:ReadMultiple>';
$xml_post_string .= '</tcit:ReadMultiple>';
$xml_post_string .= '</soapenv:Body>';
$xml_post_string .= '</soapenv:Envelope>';
$headers = array(
"Content-type: text/xml;charset=\"utf-8\"",
"Accept: text/xml",
"Cache-Control: no-cache",
"Pragma: no-cache",
"SOAPAction: `here goes my remote url which I am calling`"
);
// PHP cURL for https connection with auth
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, $soapUser.":".$soapPassword); // username and password - declared at the top of the doc
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_TIMEOUT, 300);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_post_string); // the SOAP request
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
Actually I get empty string as a response, but when I debugged I saw that problem is 401 request (Something with auth?). Anyway the script is working perfectly from my localhost, so I suppose it is related to some version incopatibility on remote Server. Let me hear your thoughts and what do you think in this configuration can be the problem.
$http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE); (this return 401)
$curl_errno= curl_errno($ch); (this returns 0)