中具有基本授权的

中具有基本授权的

本文介绍了原生 PHP 中具有基本授权的 Soap 标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要连接到 TeraData SOAP API,它现在需要使用登录凭据发送授权基本标头.我不知道如何解决这个问题.添加基本​​授权标头时,我获得了在 SoapUI 中工作的访问权限 - 请有人帮我弄明白代码:

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:

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

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]

这是我尝试设置 SoapClient 的方法:

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);

它不被接受,我只是收到一个 HTTP/1.1 401 未经授权的错误

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

推荐答案

我太笨了:

$client = new SoapClient($wsdl, array("trace" => 1, "exceptions" => 0,
                     "login" => $login, "password" => $password) );

对于 HTTP 身份验证,登录名和密码选项可用于提供凭据.

这篇关于原生 PHP 中具有基本授权的 Soap 标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 16:15