php - 将 soapenv:mustUnderstand="1" 属性添加到带有 SimpleXMLElement 对象的 SOAP 请求的标头中的安全标记
问题描述
我的问题是 PHP 中的 SOAP 标头。我无法将 mustUnderstand 属性设置为肥皂请求。你能帮我看看我的代码吗?
$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">
提前致谢。
解决方案
推荐阅读
- android - 如何在 Kotlin 中自动增加 const 值列表?
- firebase - 如何在不查询数据库中所有点的情况下从 Firestore 获取地图上的附近点
- python - Pandas .fillna() 用 NaN 替换每个值,而不是只替换 NaN 值
- python - Python 3.10 的 Matplotlib 安装问题
- html - 我想将徽标移动到左侧导航到右侧并将两侧分开?
- sql - 将两个 sql 查询合二为一,从 SEDE 的单个表中获取最流行的问题和答案
- javascript - 洗牌列 2d 数组 javascript/typescript
- tkinter - Tkinter Combox 选中的字母一次
- php - Laravel - 从模型关系中急切加载
- java - Spring Boot 微服务,端口黑名单/排除列表