我的 SOAP 请求的标头以一种奇怪的格式显示。我需要一个看起来像这样的标题:
<soap-env:header>
<wsse:security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsse:usernametoken wsu:id="UsernameToken-45">
<wsse:username>817221</wsse:username>
<wsse:password type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">1234</wsse:password>
</wsse:usernametoken>
</wsse:security>
</soap-env:header>
现在,标题看起来像这样:
<SOAP-ENV:Header>
<ns8:Security SOAP-ENV:mustUnderstand="1">
<item>
<key>UsernameToken</key>
<value>
<item>
<key>Username</key>
<value>817221</value>
</item>
<item>
<key>Password</key>
<value>
<item>
<key>_</key>
<value>1234</value>
</item>
<item>
<key>Type</key>
<value>http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText</value>
</item>
</value>
</item>
</value>
</item>
</ns8:Security>
</SOAP-ENV:Header>
大错特错。它包含和标签。我读过应该使用 SOAP_ENC_OBJECT 以正确的格式显示它,所以我在我的代码中尝试了它,但仍然无法正常工作。请看下面的代码:
$header = array(
'UsernameToken' => array(
'Username' => 817221,
'Password' => array(
'_' => 1234,
'Type' => 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText')));
$headerSoapVar = new SoapVar($header,SOAP_ENC_OBJECT);
$soapheader = new SoapHeader('http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd', "Security" , $header, true);
$client->__setSoapHeaders($soapheader);
任何帮助将不胜感激。谢谢!