如何设置这样的肥皂头(PHP)

时间:2016-04-18 10:36:02

标签: php soap

我已经将此示例发送给肥皂查询:

POST https://000.0.0.0:8181/wsForWeb/webService HTTP/1.1
Accept-Encoding: gzip,deflate
Content-Type: text/xml;charset=UTF-8
SOAPAction: ""
Authorization: Basic username:password
Content-Length: 293
Host: 000.00.00.00:8181
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://ws/">
<soapenv:Header/>
 <soapenv:Body>
  ....
 </soapenv:Body>
</soapenv:Envelope>

如何用肥皂发送这些标题?通常我会使用

$client = new soapClient(...);
$clHeader = new SoapHeader(..., array('
            'authorization' => 'Basic .......',
            'Host' => '000.000.00.00.0',
            ));
$client -> __setSoapHeaders($clHeader);

但是我收到身份验证错误。我做错了什么?

1 个答案:

答案 0 :(得分:0)

您没有在您的soap Header中传递登录凭据

$params = array(
   "login" => "username", 
   "password" => "password", 
);

$client = new SoapClient($wsdlURL, $params);

$ wsdlURL是带有Soap调用所在服务器的url的变量。

这是使用Basic Auth

实现Soap客户端的最常用方法

参考PHP官方文档:Link.

希望这会有所帮助