我正在尝试连接到受密码保护且URL为https的Web服务。在脚本发出请求之前,我不知道如何进行身份验证。似乎在我定义服务后便发出了请求。例如,如果我输入:
$client = new SoapClient("https://example.com/WSDL/nameofservice",
array('trace' => 1,)
);
然后转到浏览器上的站点,我得到:
Fatal error: Uncaught SoapFault exception:
[WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load from
'https://example.com/WSDL/nameofservice' in /path/to/my/script/myscript.php:2
Stack trace: #0 /path/to/my/script/myscript.php(2):
SoapClient->SoapClient('https://example...', Array) #1 {main} thrown in
/path/to/my/script/myscript.php on line 2
如果尝试将服务定义为Soap Server,例如:
$server= new SoapServer("https://example.com/WSDL/nameofservice");
我得到:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Body>
<SOAP-ENV:Fault>
<faultcode>WSDL</faultcode>
<faultstring>
SOAP-ERROR: Parsing WSDL:
Couldn't load from 'https://example.com/WSDL/nameofservice'
</faultstring>
</SOAP-ENV:Fault>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
我还没有尝试发送原始请求信封来查看服务器返回的内容,但这可能是一种解决方法。但是我希望有人能告诉我如何使用php内置类进行设置。我尝试将“ userName”和“ password”添加到数组,但这不好。问题是我什至无法告诉我是否要到达远程站点,更不用说它是否拒绝了请求。