2013-01-04 27 views
2

Possible Duplicate:
PHP SoapClient and a complex headerSOAPHEADER身份驗證使用PHP

我有這樣的頭結構:

<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」> 
    <wsse:UsernameToken> 
    <wsse:Username Type=」http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#UsernameToken」>votre_login</wsse:Username> 
    <wsse:Password Type=」http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText」>votre_password</wsse:Password> 
    </wsse:UsernameToken> 
    </wsse :Security> 
</soapenv :Header> 

如何使用__setSoapHeaders()方法,我把這個在PHP?

我嘗試:

$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] est requis.

+0

將該溶液[PHP SoapClient的和複雜的報頭](HTTP:/ /stackoverflow.com/questions/4319088/php-soapclient-and-a-complex-header)爲我工作,但不是優雅的,我試圖建立這個頭我們PHP數組或對象。 – ktalinu

回答

4

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

To create complex SOAP Headers, you can do something like this:

Required SOAP Header:

<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> 

Corresponding PHP code:

$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); 
+0

不適用於我。我的標題似乎更復雜... – ktalinu