如何在PHP中设置此SOAP标头

时间:2013-03-21 19:09:50

标签: php soap header

我尝试像这样设置SOAP标头:

<tns:Authentication xmlns:tns="iSklep3">
    <ApiKey xsi:type="xsd:string">abc</ApiKey>
</tns:Authentication>

我这样做:

//...
    $client = new SoapClient($wsdlServer);
    $headerBody = array("ApiKey" => "abc");
    $header = new SoapHeader("iSklep3", "Authentication", $headerBody);
    $client->__setSoapHeaders($header);
//...
//calling soap methods
...

当我调用方法时,它返回Api键是错误的,但它应该是正确的。知道SOAP头问题可以在哪里?

1 个答案:

答案 0 :(得分:1)

设置标题后,您尚未调用调用函数。

<?php

$client = new SoapClient(null, array('location' => "http://localhost/soap.php",
                                     'uri'      => "http://test-uri/"));
$header = new SoapHeader('http://soapinterop.org/echoheader/', 
                            'echoMeStringRequest',
                            'hello world');

$client->__setSoapHeaders($header);

$client->__soapCall("echoVoid", null);
?>

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