[英]Headers for connecting to a SOAP webservice using PHP
I am trying to connect to a SOAP webservice using php. 我正在尝试使用php连接到SOAP Web服务。 I am very new to using php.
我对使用php很陌生。
I can connect to the service, the test below returns a list of all the available functions of the webservice. 我可以连接到服务,下面的测试返回Web服务所有可用功能的列表。
$url = "http://...client_ip.../dkServiceDefault/dkWSItemsCGI.exe/wsdl/IItemService";
$client = new SoapClient($url);
var_dump($client->__getFunctions());
If I try to access one of these functions(ex. NumberOfModifiedItems) then I get an error stating that I need to supply a SOAP header with a username and password. 如果尝试访问这些功能之一(例如NumberOfModifiedItems),则会收到一条错误消息,指出我需要提供带有用户名和密码的SOAP标头。
According to the documentation of the SOAP service the header needs to look like this: 根据SOAP服务的文档,标头需要如下所示:
<soap:Header>
<q1:BasicSecurity id="h_id1" xmlns:q1="urn:dkWSValueObjects">
<Username xsi:type="xsd:string">username</Username>
<Password xsi:type="xsd:string">password</Password>
</q1:BasicSecurity>
</soap:Header>
How can I make this header in php? 如何在php中创建此标头? How do I attach it to the SoapClient?
如何将其附加到SoapClient? I have a username and password but I can't figure out how to create the exact header to send to the webservice.
我有一个用户名和密码,但是我不知道如何创建确切的标头以发送到Web服务。 I have tried following several tutorials, but I just can't seem to get it to work.
我尝试了以下几个教程,但是似乎无法正常工作。
You may pass SOAP headers with SoapHeader class and SoapClient::__setSoapHeaders method: 您可以使用SoapHeader类和SoapClient :: __ setSoapHeaders方法传递SOAP标头:
<?php
$url = "http://...client_ip.../dkServiceDefault/dkWSItemsCGI.exe/wsdl/IItemService";
$client = new SoapClient($url);
$namespace = "urn:dkWSValueObjects";
$authentication = array(
'Username' => 'yourname',
'Password' => 'yourpassword'
);
$header = new SoapHeader($namespace, 'BasicSecurity', $authentication, false);
$client->__setSoapHeaders($header);
var_dump($client->__getFunctions());
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.