欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

在本机PHP中使用Authorization Basic的Soap Header(Soap Header with Authorization Basic in native PHP) 有大用

在本机PHP中使用Authorization Basic的Soap Header(Soap Header with Authorization Basic in native PHP)

我需要连接到TeraData SOAP API,现在需要使用登录凭据发送Authorization Basic Header。 我不知道如何解决这个问题。 我在添加基本授权标题时在SoapUI中使用了访问权限 - 请任何人都可以帮助我直接获取代码:

这是Header SoapUI发送的,并且响应很好:

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]

这是我试图设置我的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);

它不被接受,我只是得到一个HTTP / 1.1 401 Unauthorized Error

stacktrace向我显示我发送的标题 - 那里缺少授权部分。

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

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

原文:https://stackoverflow.com/questions/35360282


来自  https://www.656463.com/wenda/zbjPHPzsyAuthorizationBasicdSoap_147


普通分类: