title: Access Exchange Web Services with PHP and cURL
body: <p>Hello,</p>
  
  <p>I am currently writing a client to access a Microsoft Exchange server and read contacts, appointments etc. from it.</p>
  
  <p>Through days of searching I've been able to connect to the EWS via PHP's Soap client and a custom HTTPS Stream wrapper. <a href="http://rabaix.net/en/articles/2008/03/13/using-soap-php-with-ntlm-authentication">This</a> website helped me greatly at this point.</p>
  
  <p>Everything worked fine on my Windows 7 machine using XAMPP</p>
  
  <p>Now I uploaded my project to a Debian 6.0 Squeeze development machine that has exactly the same configuration as my Windows machine regarding the web-server, php settings, mysql settings etc. but it just wont work anymore</p>
  
  <p>The debian machine can resolve and ping the exchange server without problems</p>
  
  <p>I nailed the actual problem down to a point, where cURL isn't able to retrieve the WSDL file of the EWS</p>
  
  <p>It always receives an empty response and a 401 (Unauthorized) status code</p>
  
  <p>The credentials I use are correct, the same credentials work on my windows machine</p>
  
  <p>I extracted the faulty piece of code and tried running it stand-alone, it looks like this:</p>
  
  <pre><code>    echo "Trying to get https://".$cfg[ 'Exchange.Server' ]."/EWS/Services.wsdl&lt;br&gt;";
      $curl = curl_init( 'https://'.$cfg[ 'Exchange.Server' ].'/EWS/Services.wsdl' );
      curl_setopt( $curl, CURLOPT_RETURNTRANSFER,     true );
      curl_setopt( $curl, CURLOPT_HTTP_VERSION,       CURL_HTTP_VERSION_1_1 );
      curl_setopt( $curl, CURLOPT_HTTPAUTH,           CURLAUTH_NTLM );
      curl_setopt( $curl, CURLOPT_USERPWD,            $cfg[ 'Exchange.User' ].':'.$cfg[ 'Exchange.Password' ] );
      curl_setopt( $curl, CURLOPT_SSL_VERIFYPEER,     false );
      curl_setopt( $curl, CURLOPT_SSL_VERIFYHOST,     false );
  
      echo '&lt;pre&gt;';
      $response = curl_exec( $curl );
      $info = curl_getinfo( $curl );
  
      var_dump( $info );
      var_dump( $response );
  
      curl_close( $curl );
  </code></pre>
  
  <p>The result I receive here is the mentioned 401 status code and an empty response
  When I call the same url in my browser or with the same code on my windows machine, I get the WSDL file I want</p>
  
  <p>Actually I can't even tell if this is a linux-based problem or if I do something wrong at some point, I'm struggling with this for 2 days now.</p>
  
  <p>Is there someone that may be able to find my mistake or tell me the reason why it doesn't work?</p>
  
  <p>I may provide any further needed information on demand</p>