我正在尝试使用 PHP SOAP 客户端使用 SOAP 服务,但失败并显示以下消息:
SoapFault: SOAP-ERROR: Parsing WSDL: Couldn't load from 'https://domain.com/webservice.asmx?wsdl' : failed to load external entity "https://domain.com/webservice.asmx?wsdl"\n in /Users/andrewdchancox/Projects/test/testsoap.php on line 10
Run Code Online (Sandbox Code Playgroud)
我已经下载了 wsdl 文件并从 apache 的本地实例提供了它,它加载没有任何问题。我唯一能想到的可能是 Web 服务正在使用自签名证书通过 SSL 运行 - 当我 wget wsdl 时,我收到以下错误:
--2012-09-11 16:28:39--
https://domain.com/webservice.asmx?wsdl
Resolving domain.com (domain.com)... 11.111.111.11
Connecting to domain.com (domain.com)|11.111.111.11|:443... connected.
ERROR: The certificate of ‘domain.com’ is not trusted.
ERROR: The certificate of ‘domain.com’ hasn't got a known issuer.
Run Code Online (Sandbox Code Playgroud)
我已经搜索并彻底阅读了 PHP SOAP 客户端的 PHP 文档 - http://php.net/manual/en/class.soapclient.php及其构造函数 - http://www.php.net/manual/ en/soapclient.soapclient.php并没有找到任何帮助。
有人有任何想法吗?
这是两年前的事,但我认为它值得一个答案。
PHP 中的 SoapClient 类使用 PHP 流通过 HTTP 进行通信。出于各种原因,基于 PHP 流的 SSL 是不安全的1,但在这种情况下,您的问题是它太安全了。
解决方案的第一步是stream_context在构建 SoapClient 2时使用该选项。这将允许您指定更高级的 SSL 设置3:
// Taken from note 1 below.
$contextOptions = array(
'ssl' => array(
'verify_peer' => true,
'cafile' => '/etc/ssl/certs/ca-certificates.crt',
'verify_depth' => 5,
'CN_match' => 'api.twitter.com',
'disable_compression' => true,
'SNI_enabled' => true,
'ciphers' => 'ALL!EXPORT!EXPORT40!EXPORT56!aNULL!LOW!RC4'
)
);
$sslContext = stream_context_create($contextOptions);
// Then use this context when creating your SoapClient.
$soap = new SoapClient('https://domain.com/webservice.asmx?wsdl', array('stream_context' => $sslContext));
Run Code Online (Sandbox Code Playgroud)
您的问题的理想解决方案是创建您自己的 CA 证书,使用它来签署 SSL 证书,然后将您的 CA 证书添加到cafile. 更好的方法可能是只在 中拥有该证书cafile,以避免某些流氓 CA 为您的域签署其他人的证书,但这并不总是实用的。
如果您所做的工作不需要安全(例如在测试期间),您还可以在流上下文中使用 SSL 设置来降低连接的安全性。该选项allow_self_signed将允许自签名证书:
$contextOptions = array(
'ssl' => array(
'allow_self_signed' => true,
)
);
$sslContext = stream_context_create($contextOptions);
$soap = new SoapClient('https://domain.com/webservice.asmx?wsdl', array('stream_context' => $sslContext));
Run Code Online (Sandbox Code Playgroud)
链接:
| 归档时间: |
|
| 查看次数: |
7577 次 |
| 最近记录: |