Soap Header with Authorization Basic in native PHP
<p>i need to connect to TeraData SOAP API which now demands a Authorization Basic Header to be sent with the login credentials. I do not know how to adress the  problem. I got the access working in SoapUI when adding Basic Authorization Header - please can anyone help me to get the code straight:</p>

<p>Here's the Header SoapUI sends and the response is good:</p>

<pre><code>POST http://example.com/api/soap/v6 HTTP/1.1
Accept-Encoding: gzip,deflate
Content-Type: text/xml;charset=UTF-8
SOAPAction: ""
Content-Length: 302
Host: example.com
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)
Authorization: Basic [user&amp;pass-base64-encoded]
</code></pre>

<p>Here's how i am trying to set up my SoapClient:</p>

<pre><code>$namespace =  "http://ecircle.com/developer/ecmapi";
$wsdl = "https://sslh.teradatadmc.com/teradata/api/soap/v6?wsdl";
$client = new SoapClient($wsdl, array("trace" =&gt; 1, "exceptions" =&gt; 0));
$login = 'xxx';
$password = 'yyy';
$header = new SoapHeader($namespace, 'Authorization: Basic',   
base64_encode("$login:$password"));
$client-&gt;__setSoapHeaders($header);
</code></pre>

<p>it's not accepted and i just get an HTTP/1.1 401 Unauthorized Error</p>

<p>The stacktrace shows me the header that i sent - the Authorization part is missing there.</p>

<pre><code>public '__last_request_headers' =&gt; string 'POST /api/soap/v6 HTTP/1.1
Host: example.com
Connection: Keep-Alive
User-Agent: PHP-SOAP/5.5.12
Content-Type: text/xml; charset=utf-8
SOAPAction: ""
Content-Length: 584
</code></pre>