title: How can I send SOAP XML via Curl and PHP?
body: <p>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 can't see how.  </p>
  
  <p>I have an ASP version which works fine with the same URL and data. I think it's just a PHP/Curl thing.</p>
  
  <p>I currently have the following code (the <code>CURLOPT_POSTFIELDS</code> data is a valid SOAP envelope string):</p>
  
  <pre><code>$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,     '&lt;soap:Envelope&gt;...&lt;/soap:Envelope&gt;'); 
  curl_setopt($soap_do, CURLOPT_HTTPHEADER,     array('Content-Type: text/xml; charset=utf-8', 'Content-Length: '.strlen('&lt;soap:Envelope&gt;...&lt;/soap:Envelope&gt;') ));
  
  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';
  }
  </code></pre>
  
  <p>So any ideas why it just errors all the time?</p>
  
  <p>The ASP version works fine! The code is:</p>
  
  <pre><code>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('&lt;soap:Envelope&gt;...&lt;/soap:Envelope&gt;')
  </code></pre>