SOAPclient PHP中的头文件


Header in SOAPclient PHP

我使用SOAP的经验很少。如何在soap客户机中指定用户名和密码?请参见下面WSDL的相应部分。

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xx="xx.services.soap">
<soapenv:Header>
  <cb:UserName>_SNIP_</cb:UserName>
  <cb:Password>_SNIP_</cb:Password>
</soapenv:Header>
<soapenv:Body>
  <cb:checkOrderable>
     <arg2>
        <EAN>9789084999820</EAN>
        <DeliveryChannel>CBW</DeliveryChannel>
     </arg2>
  </cb:checkOrderable>
</soapenv:Body>
</soapenv:Envelope>

我有以下代码,但服务器响应用户名和密码没有给出:

$client = new SoapClient("https://xxxxx...xxxxxService?wsdl");
$params = array(
  "UserName" => "abc",
  "Password" => "def",
  "EAN" => $ean,
  "DeliveryChannel" => "xxx",
);
$response = $client->checkOrderable( $params );
print_r( $response );

您应该使用loginpassword参数进行BASIC验证。也值得添加'trace' => true。如果您的WSDL是密码保护的,那么您需要将这些传递给SoapClient构造函数。