0

我正在使用以下代码使用 PHP 创建一个 SOAPHEADER

// Instantiate the client.
$client = new SoapClient($wsdl_url, array('trace' => 1));
// Pass along login information
$soap_header = new SoapHeader(
$api_url,
'APICredentials',
array(
    'DeveloperKey' => $developerKey,
    'Password' => $password
    )
);
$client->__setSoapHeaders($soap_header);

创造了这个

<SOAP-ENV:Header>
    <ns2:APICredentials>
       <item>
         <key>DeveloperKey</key>
         <value>********</value>
       </item>
       <item>
         <key>Password</key>
         <value>********</value>
       </item>
    </ns2:APICredentials>
</SOAP-ENV:Header>

如何更改 PHP 代码以创建以下标头?

<soapenv:Header> 
<web:APICredentials> 
<web:DeveloperKey>...</web:DeveloperKey> 
<web:Password>...</web:Password> 
</web:APICredentials> 
</soapenv:Header> 
4

1 回答 1

0

您可以使用 $soap_client->__setSoapHeaders($header); 完全手动设置。

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: 

<?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); 

来源: http: //php.net/manual/en/soapclient.setsoapheaders.php

于 2012-10-23T09:48:45.290 回答