简体   繁体   English

如何在PHP中设置此SOAP标头

[英]How to set this SOAP header in PHP

I try to set SOAP header like this: 我尝试像这样设置SOAP标头:

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

I make it this way: 我这样做:

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

When I call methods, it returns Api key is wrong, but it should be right. 当我调用方法时,它返回的Api键是错误的,但是应该是正确的。 Knows somebody where the problem of SOAP header can be? 知道有人SOAP标头的问题在哪里吗?

You haven't called the call function after setting the header. 设置标题后,您尚未调用调用函数。

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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