简体   繁体   中英

How to construct SOAP header using SoapClient in PHP

I need to make soap calls which include headers like this:

<soap:Header>
    <Agency xmlns="http://schemas.costacrociere.com/WebAffiliation">
        <Code>1111</Code>
        <Culture />
    </Agency>
    <Partner xmlns="http://schemas.costacrociere.com/WebAffiliation">
        <Name>AAAA</Name>
        <Password>XXXX</Password>
    </Partner>
</soap:Header>

How to do that in PHP using SoapClient? Plz help :)

I did it:

$ns="http://schemas.costacrociere.com/WebAffiliation";

//Body of the Soap Header.
$headerbody1 = array("Name" => "AAAA", "Password" => "XXXX");
$headerbody2 = array("Code" => "1111");

//Create Soap Header.       
$header[] = new SOAPHeader($ns, 'Partner', $headerbody1);
$header[] = new SOAPHeader($ns, 'Agency', $headerbody2);

//set the Headers of Soap Client.
$client->__setSoapHeaders($header);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM