soap - 使用 PHP 连接到受 WS-Security 保护的 Soap Web 服务
问题描述
我有这个 wsdl 文件女巫没有密码保护,我需要通过 php soap 客户端调用它:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:afe4="http://gsis.ggps.interoperability/Afe4Interface">
<soapenv:Header>
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken xmlns:wsse='http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd' >
<wsse:Username>****************************</wsse:Username>
<wsse:Password Type='http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText'>*****************************</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</soapenv:Header>
<soapenv:Body>
其他参数听 </soapenv:Body> </soapenv:Envelope>
我正在尝试通过 php soapheader 连接:
class WsseAuthHeader extends SoapHeader {
private $wss_ns = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd';
function __construct($user, $pass, $ns = null) {
if ($ns) {
$this->wss_ns = $ns;
}
$auth = new stdClass();
$auth->Username = new SoapVar($user, XSD_STRING, NULL, $this->wss_ns, NULL, $this->wss_ns);
$auth->Password = new SoapVar($pass, XSD_STRING, NULL, $this->wss_ns, NULL, $this->wss_ns);
$username_token = new stdClass();
$username_token->UsernameToken = new SoapVar($auth, SOAP_ENC_OBJECT, NULL, $this->wss_ns, 'UsernameToken', $this->wss_ns);
$security_sv = new SoapVar(
new SoapVar($username_token, SOAP_ENC_OBJECT, NULL, $this->wss_ns, 'UsernameToken', $this->wss_ns),
SOAP_ENC_OBJECT, NULL, $this->wss_ns, 'Security', $this->wss_ns);
parent::__construct($this->wss_ns, 'Security', $security_sv, true);
}
****************** }
$wsse_header = new WsseAuthHeader($username, $password);
but it replies "A security error was encountered when verifying the message"
witch according to the manual means wrong usr or password.
Via postman i can connect.
Any suggestions?
解决方案
事实证明,将标头设置为原始数据可以解决问题。谢谢你的时间!!!
推荐阅读
- vb.net - 石头剪刀布游戏画框不换
- oracle - 从 Oracle DB 加载数据时,列值作为子字符串出现
- java - 类中的Java android房间列表无法弄清楚如何将此字段保存到数据库中
- c - STM32 无法通过 HAL_UART_Recceive_IT 接收数据
- linux - 为什么即使没有/dev/shm shm_open() 也会成功?
- html - 嵌入式 PDF 在按键时刷新
- mysql - Mysql集合代数运算
- php - 为什么我在 Laravel 上的 Ratcher 服务器不工作?
- python - 共享不同标签的点列表中的相图
- entity-framework-core - 在服务器上使用 MAX 评估 EF 查询