[英]Headers for connecting to a SOAP webservice using PHP
我正在嘗試使用php連接到SOAP Web服務。 我對使用php很陌生。
我可以連接到服務,下面的測試返回Web服務所有可用功能的列表。
$url = "http://...client_ip.../dkServiceDefault/dkWSItemsCGI.exe/wsdl/IItemService";
$client = new SoapClient($url);
var_dump($client->__getFunctions());
如果嘗試訪問這些功能之一(例如NumberOfModifiedItems),則會收到一條錯誤消息,指出我需要提供帶有用戶名和密碼的SOAP標頭。
根據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>
如何在php中創建此標頭? 如何將其附加到SoapClient? 我有一個用戶名和密碼,但是我不知道如何創建確切的標頭以發送到Web服務。 我嘗試了以下幾個教程,但是似乎無法正常工作。
您可以使用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.