SOAPclient PHP中的标头

时间:2015-06-08 06:39:47

标签: php soap

我对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 );

1 个答案:

答案 0 :(得分:0)

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