问题
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:
Here's the Header SoapUI sends and the response is good:
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&pass-base64-encoded]
Here's how i am trying to set up my SoapClient:
$namespace = "http://ecircle.com/developer/ecmapi";
$wsdl = "https://sslh.teradatadmc.com/teradata/api/soap/v6?wsdl";
$client = new SoapClient($wsdl, array("trace" => 1, "exceptions" => 0));
$login = 'xxx';
$password = 'yyy';
$header = new SoapHeader($namespace, 'Authorization: Basic',
base64_encode("$login:$password"));
$client->__setSoapHeaders($header);
it's not accepted and i just get an HTTP/1.1 401 Unauthorized Error
The stacktrace shows me the header that i sent - the Authorization part is missing there.
public '__last_request_headers' => 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
回答1:
man i was so stupid:
$client = new SoapClient($wsdl, array("trace" => 1, "exceptions" => 0,
"login" => $login, "password" => $password) );
For HTTP authentication, the login and password options can be used to supply credentials.
回答2:
That's because you should encode your login credentials this way:
base64_encode("$login:$password")
instead of:
base64_encode($login) . ':' . base64_encode($password)
来源:https://stackoverflow.com/questions/35360282/soap-header-with-authorization-basic-in-native-php