我的问题是PHP中的SOAP Header。我不能将mustUnderstand属性设置为soap request。 您能帮我提供我的代码吗?
$root = new SimpleXMLElement('<header/>');
$security = $root->addChild('wsse:Security', null, $ns_wsse);
$security->addAttribute('soapenv:mustUnderstand', true);
$usernameToken = $security->addChild('wsse:UsernameToken', null, $ns_wsse);
$usernameToken->addChild('wsse:Username', $username, $ns_wsse);
$usernameToken->addChild('wsse:Password', $password, $ns_wsse)->addAttribute('Type', $password_type);
$usernameToken->addChild('wsse:Nonce', $encoded_nonce, $ns_wsse)->addAttribute('EncodingType', $encoding_type);
$usernameToken->addChild('wsu:Created', $tm_created, $ns_wsu);
// Recovering XML value from that object
$root->registerXPathNamespace('wsse', $ns_wsse);
Header('Content-type: text/xml');
$full = $root->xpath('/header/wsse:Security');
$auth = $full[0]->asXML();
echo $auth;
输出:
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" mustUnderstand="1">
<wsse:UsernameToken>
<wsse:Username></wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-usernametoken-profile-1.0#PasswordText"></wsse:Password>
<wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">MTk5Njg4NjYzOQ==</wsse:Nonce>
<wsu:Created xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">2018-08-13T10:57:52Z</wsu:Created>
</wsse:UsernameToken>
</wsse:Security>
我想添加soapenv:mustUnderstand =“ 1”属性,而不是mustUnderstand =“ 1”。 添加了其他属性,但是无法添加“ soapenv:”,因此无法从Web服务接收数据。它给出了错误。
预期的标题:
<wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
谢谢。