title: Soap client, how to call a function over HTTPS with Basic HTTP Authentication
body: <p>This problem has been killing me for the entire day.</p>
  
  <p>I have a client web service https://<strong><em>*</em></strong>.asmx?WSDL, with Basic HTTP Authentication..</p>
  
  <p>If I use SoapUI to connect to the webservice, everything works perfectly with no errors whatsoever..</p>
  
  <p>The problem is when I switch to PHP...</p>
  
  <p>I managed to connect to it, and I can get the function list from the server using soapclient extension for php ( I'm using PHP 5.3.0 ).</p>
  
  <p>When I try to call a function using the soapclient extension for PHP I get the following error:</p>
  
  <blockquote>
    <p>Fatal error: Uncaught SoapFault exception: [HTTP] Error Fetching http headers in
    C:\www\xpto_Atestes\soapclient.php:26 Stack trace: #0 [internal function]: >SoapClient->__doRequest('<em>*</em>**...', 'http://<strong><em>*</em>***</strong>...', 1, 0) #1 >C:\www\xpto_Atestes\soapclient.php(26): SoapClient->__soapCall('login', Array) #2 {main} >thrown in C:\www\xpto_Atestes\soapclient.php on line 26</p>
  </blockquote>
  
  <p>More clear error ( when I do a print_r of the result of the call):</p>
  
  <blockquote>
    <p>[faultstring] => Error Fetching http headers<br>
    [faultcode] => HTTP</p>
  </blockquote>
  
  <p>With the following headers being sent:</p>
  
  <blockquote>
    <p>POST /<strong><em>*</em></strong>.asmx HTTP/1.1 Host: <strong><em>*</em></strong>.pt Connection: Keep-Alive User-Agent: >PHP-SOAP/5.3.0 Content-Type: text/xml; charset=utf-8 SOAPAction: "http://<strong><em>*</em>*</strong>/Login" >Content-Length: 264 Authorization: Basic AUTHSECRETPASS</p>
  </blockquote>
  
  <p>I'm calling it like this:</p>
  
  <blockquote>
    <p>$soapParams = array('login' => 'HTTP_LOGIN',<br>
    'password' => 'HTTP_PASS',<br>
    'authentication' => SOAP_AUTHENTICATION_BASIC,<br>
    'trace' => 1,<br>
    'exceptions' => 0<br>
    );<br>
    $client = new SoapClient("https://<strong><em>*</em>***</strong>.asmx?WSDL", $soapParams);
    echo "Connected<br />";
    $params = array('account' => '', 'msisdn'=>'NUMBER', 'password'=>'PASSWORD');
    $result = $client->__soapCall("login", $params);</p>
  </blockquote>
  
  <p>After a while googling and trying to find out what the problem could be, I switched to nusoap.. which to my misery it gave an error also:</p>
  
  <blockquote>
    <p><strong>Error</strong></p>
    
    <p>HTTP Error: socket read of headers timed out</p>
    
    <p><strong>Request</strong></p>
    
    <p>POST /<strong><em>*</em>*</strong>.asmx HTTP/1.0
    Host: <strong><em>*</em></strong>.pt
    User-Agent: NuSOAP/0.9.5 (1.123)
    Content-Type: text/xml; charset=ISO-8859-1
    SOAPAction: "http://<strong><em>*</em>***</strong>/Login"
    Authorization: Basic AUTHSECRETPASS
    Content-Length: 481</p>
    
    <p>NUMBERPASSWORD</p>
    
    <p><strong>Response</strong></p>
  </blockquote>
  
  <p>I'm calling it like this:</p>
  
  <blockquote>
    <p>$client = new nusoap_client("https://<strong><em>*</em>*</strong>.asmx?WSDL", true);<br>
    $client->setCredentials('HTTPUSER','HTTPPASS','basic');<br>
    $params = array(
    'account' => '',
    'msisdn'=>'NUMBER',
    'password'=>'PASSWORD'
    );<br>
    $result = $client->call('Login', $params);</p>
  </blockquote>
  
  <p>With nusoap I also tried to enable enable curl extension to make the calls:</p>
  
  <blockquote>
    <p>$client->setUseCurl(true);</p>
  </blockquote>
  
  <p>But no such luck, it kept on giving an error:</p>
  
  <blockquote>
    <p>HTTP Error: cURL ERROR: 56: Failure when receiving data from the peer
    url: http://<strong><em>*</em>**<em>*</em>**<em>*</em>**</strong>.asmx<br>
    content_type:<br>
    http_code: 0<br>
    header_size: 0<br>
    request_size: 750<br>
    filetime: -1<br>
    ssl_verify_result: 0<br>
    redirect_count: 0<br>
    total_time: 21.015<br>
    namelookup_time: 0<br>
    connect_time: 0<br>
    pretransfer_time: 0<br>
    size_upload: 462<br>
    size_download: 0<br>
    speed_download: 0<br>
    speed_upload: 21<br>
    download_content_length: -1<br>
    upload_content_length: -1<br>
    starttransfer_time: 0<br>
    redirect_time: 0  </p>
  </blockquote>
  
  <p>I'm 100% sure that nothing is wrong with the webservice, if I can call it from SoapUI without any problem I don't see why I can't call it from PHP.</p>
  
  <p>I rally don't know what more I can do.. I think I tried everything...</p>
  
  <p>Edit: I just tried another Soap Class for PHP, this time from Zend..</p>
  
  <p>The result is:</p>
  
  <blockquote>
    <p>Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load from 'https://<strong><em>*</em>*</strong>.asmx?WSDL' : failed to load external entity "https://<strong><em>*</em></strong>.asmx?WSDL" in C:\www\xpto_Atestes\Zend\Soap\Client\Common.php:51 Stack trace:<br>
    #0 C:\www\xpto_Atestes\Zend\Soap\Client\Common.php(51): SoapClient->SoapClient('https://<strong><em>*</em>*</strong>...', Array)<br>
    #1 C:\www**<strong><em>*</em>*</strong>_Atestes\Zend\Soap\Client.php(1032): Zend_Soap_Client_Common->__construct(Array, 'https://<strong><em>*</em>*</strong>...', Array)<br>
    #2 C:\www**<strong>**</strong>_Atestes\Zend\Soap\Client.php(1188): Zend_Soap_Client->_initSoapClientObject()<br>
    #3 C:\www**<strong><em>*</em></strong>_Atestes\Zend\Soap\Client.php(1112): Zend_Soap_Client->getSoapClient() #4 [internal function]: Zend_Soap_Client->__call('Login', Array)<br>
    #5 C:\www**<strong>**</strong>_Atestes\zend.php(28): Zend_Soap_Client->Login(Array)<br>
    #6 {main} thrown in</p>
  </blockquote>