tags:

views:

830

answers:

3

Hi.
This has been bugging me for days, i'm trying to send a SOAP post via curl but i just keep getting a 'couldn't connect to host' error but i really cant see how.
I have an asp version which works fine with the same url and data, i think it's just a php/curl thing...? I currently have the following code (the CURLOPT_POSTFIELDS data is a valid soap envelope string)

    $soap_do = curl_init();
    curl_setopt($soap_do, CURLOPT_URL,            "https://xxx.yyy.com:517/zzz.asmx" );
    curl_setopt($soap_do, CURLOPT_CONNECTTIMEOUT, 10);
    curl_setopt($soap_do, CURLOPT_TIMEOUT,        10);
    curl_setopt($soap_do, CURLOPT_RETURNTRANSFER, true );
    curl_setopt($soap_do, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($soap_do, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($soap_do, CURLOPT_POST,           true );            
    curl_setopt($soap_do, CURLOPT_POSTFIELDS,     '<soap:Envelope>...</soap:Envelope>'); 
    curl_setopt($soap_do, CURLOPT_HTTPHEADER,     array('Content-Type: text/xml; charset=utf-8', 'Content-Length: '.strlen('<soap:Envelope>...</soap:Envelope>') ));

    if(curl_exec($soap_do) === false)
    {                
        $err = 'Curl error: ' . curl_error($soap_do);
        curl_close($soap_do);
        return $err;
    }
    else
    {
        curl_close($soap_do); 
        return 'Operation completed without any errors';
    }

So any ideas why it just errors all the time?

The asp version works fine! The code is;

Set xmlhttp = server.Createobject("MSXML2.ServerXMLHTTP")
xmlhttp.Open "POST","https://xxx.yyy.com:517/zzz.asmx"
xmlhttp.setRequestHeader "Content-Type", "text/xml; charset=utf-8"
xmlhttp.Send('<soap:Envelope>...</soap:Envelope>')

+1  A: 

Try and set the port number using CURLOPT_PORT as perhaps it's not liking it as part of the URL?

Alistair
Already tried that one and it doesn't work :/ Thanks though for the idea
danrichardson
+1  A: 

I had to use

        $headers = array(             
        "Content-type: text/xml;charset=\"utf-8\"", 
        "Accept: text/xml", 
        "Cache-Control: no-cache", 
        "Pragma: no-cache", 
        "SOAPAction: \"run\"", 
        "Content-length: ".strlen($xml),
    ); 

and

 curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); 
Dom Hodgson
Thanks Dom, I will give that a shot later on and let you know if it worked for me :)
danrichardson
Sadly this didn't work for me :(
danrichardson
A: 

Your also using the wrong Content-type, application/xml is the correct type. But that shouldn't make any difference to the cURL request.

Adam