1

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)
Nikanor
  • 262
  • 1
  • 5
  • 17
  • First think is to analyse what `curl_error` has to say... – sidyll Mar 03 '17 at 22:00
  • I updated the question – Nikanor Mar 03 '17 at 22:04
  • I'm sorry, I misread your question on the first read. Well, if it returns 401 then it is just a 401, unauthorised. Does the server has any whitelist functionality? Considering your credentials are correct. Can you access any log on the server side to see more details on why it was refused? – sidyll Mar 03 '17 at 22:11
  • Thanks for the tips. Credentials are correct because same code is working from my localhost. Whitelist seems interesting, you mean remote server which I am fetching has blocked the ip of my server for some reason? I don't have access to the fetching url server – Nikanor Mar 03 '17 at 22:15
  • Please try analysing the request sent, like described [here](http://stackoverflow.com/a/24148421/557306) for example. Compare if there is any difference between your local and server requests. Shouldn't be, but who knows, there may be a software difference we are skipping here. If there is no difference, then it might be network related. I'd then try to reduce the request to a bare minimal that still reproduces the error to continue analysing. – sidyll Mar 03 '17 at 22:21

0 Answers0