title: Calling SOAP WSDL Webservice using CURL
body: <p>I'm trying to call a SOAP webservice using CURL and it is not working. This is the code I have used to invoke webservice using soap client</p>
  
  <pre><code> (object)$ProgramClient = new SoapClient('https://mywebserviceurl?wsdl',array(
  'login' =&gt; "username", 'password' =&gt; "password",
  'location' =&gt; 'https://someotherurl'
  ));
  
  (object)$objResult1 = $ProgramClient-&gt;GetEvents(array (
  'EventsRequest' =&gt; array (
  'Source' =&gt; array (
  'SourceId' =&gt; 'SOURCEID', 'SystemId' =&gt; 'SYTEMID')
   )));
  
   $event_info = $objResult1-&gt;EventsResponse;
  </code></pre>
  
  <p>This is working fine and I converted this call using CURL and it stopped working. Here is my code using CURL</p>
  
  <pre><code>      $credentials = "username:password"; 
        $url = "https://mywebserviceurl?wsdl";
        $body = '&lt;?xml version="1.0" encoding="utf-8"?&gt;
                          &lt;soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"&gt;
                            &lt;soap:Body&gt;
                              &lt;GetEvents xmlns="https://umywebserviceurl?wsdl"&gt; 
                               &lt;/GetEvents &gt;
                            &lt;/soap:Body&gt;
                          &lt;/soap:Envelope&gt;'; 
          $headers = array( 
  'Content-Type: text/xml; charset="utf-8"', 
  'Content-Length: '.strlen($body), 
  'Accept: text/xml', 
  'Cache-Control: no-cache', 
  'Pragma: no-cache', 
  'SOAPAction: "GetEvents"'
  ); 
  
    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_URL, $url); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
    curl_setopt($ch, CURLOPT_TIMEOUT, 60); 
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
     curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
  
    // Stuff I have added
   curl_setopt($ch, CURLOPT_POST, true); 
   curl_setopt($ch, CURLOPT_POSTFIELDS, $body); 
   curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
   curl_setopt($ch, CURLOPT_USERPWD, $credentials);
  
    $data = curl_exec($ch);
  
  
    echo '&lt;pre&gt;';
    print_r($data);
  </code></pre>
  
  <p>Could anyone tell me what I'm missing here..</p>
  
  <p>Regards
  Jayesh</p>