2

可能重复:
PHP SoapClient 和复杂的标头

我有这个标题结构:

<soapenv:Header>
  <wsse:Security xmlns:wsse=”http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd” soapenv:mustUnderstand=”0”&gt;
    <wsse:UsernameToken>
    <wsse:Username Type=”http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#UsernameToken”&gt;votre_login</wsse:Username>
    <wsse:Password Type=”http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText”&gt;votre_password</wsse:Password>
    </wsse:UsernameToken>
  </wsse :Security>
</soapenv :Header>

我如何使用方法将其放入 php 中__setSoapHeaders()

我试过了:

$auth = array(
            'UsernameToken' => array(
                'Username' => '*****',
                'Password' => '*****'
            )
        );
$header = new SoapHeader('http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd','Security',$auth, 0);
$client->__setSoapHeaders($header);

我有这个错误:

com.ibm.wsspi.wssecurity.SoapSecurityException: WSEC5509E: Un jeton de sécurité dont le type est [ http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile -1.0#UsernameToken] 需要。

4

1 回答 1

4

来自: http: //php.net/manual/en/soapclient.setsoapheaders.php#93460

要创建复杂的 SOAP 标头,您可以执行以下操作:

所需的 SOAP 标头:

<soap:Header> 
 <RequestorCredentials xmlns="http://namespace.example.com/"> 
  <Token>string</Token> 
  <Version>string</Version> 
  <MerchantID>string</MerchantID> 
  <UserCredentials> 
   <UserID>string</UserID> 
   <Password>string</Password> 
  </UserCredentials> 
 </RequestorCredentials> 
</soap:Header> 

对应的PHP代码:

$ns = 'http://namespace.example.com/'; //Namespace of the WS. 

//Body of the Soap Header. 
$headerbody = array('Token' => $someToken, 
                'Version' => $someVersion, 
                'MerchantID'=>$someMerchantId, 
                  'UserCredentials'=>array('UserID'=>$UserID, 
                                         'Password'=>$Pwd)); 

//Create Soap Header.        
$header = new SOAPHeader($ns, 'RequestorCredentials', $headerbody);        

//set the Headers of Soap Client. 
$soap_client->__setSoapHeaders($header);
于 2013-01-04T16:59:24.913 回答