PHP SoapClient标题.在子节点中获取命名空间时遇到问题.这是我使用的代码:
$security = new stdClass; $security->UsernameToken->Password = 'MyPassword'; $security->UsernameToken->Username = 'MyUsername'; $header[] = new SOAPHeader('http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd','Security',$security); $client->__setSoapHeaders($header);
这是它生成的XML:
<ns2:Security> <UsernameToken> <Password>MyPassword</Password> <Username>MyUsername</Username> </UsernameToken> </ns2:Security>
这是我想要生成的XML:
<ns2:Security> <ns2:UsernameToken> <ns2:Password>MyPassword</ns2:Password> <ns2:Username>MyUsername</ns2:Username> </ns2:UsernameToken> </ns2:Security>
我需要将命名空间引用到UsernameToken,Password和Username节点.任何帮助将非常感激.
谢谢.
弄清楚了.我使用了嵌套的SoapVars和数组.
$ns_s = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd'; $node1 = new SoapVar('MyUsername',XSD_STRING,null,'Username',$ns_s); $node2 = new SoapVar('MyPassword','Password',$ns_s); $token = new SoapVar(array($node1,$node2),SOAP_ENC_OBJECT,'UsernameToken',$ns_s); $security = new SoapVar(array($token),$ns_s); $header[] = new SOAPHeader($ns_s,$security,false);
这花了太多的努力和思考