【发布时间】:2016-06-21 17:53:46
【问题描述】:
我一直在尝试使用欧盟的网站来验证 TIN 号码 (Europa TIN validation website - there is a WSDL available at the bottom of the page)
我遇到的问题是,当我尝试创建一个新的 SoapClient 时,该函数在构建客户端时立即失败。起初我遇到“无法加载外部实体”,我认为这是因为 WSDL 具有安全连接。在四处搜索后,我发现一些答案说问题可能与证书过时有关,并且在这种情况下最新版本的 PHP 会抛出错误,所以我禁用了证书验证:
// Stream context due to certificate problems
$streamContext = stream_context_create(array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
));
但现在我收到另一个错误:“无法打开流:HTTP 请求失败!HTTP/1.1 502 Bad Gateway”。关于如何解决这个问题的任何想法?如果我从链接中删除“https://”,我会得到与以前相同的结果,并显示“无法加载外部实体”消息。
现在这是真正的大脑选择器。如果我尝试使用 chrome 的扩展“Boomerang”来测试 WSDL 上的 SOAP 调用,它绝对可以完美运行,所以我不知道这里出了什么问题……任何人都可以通过尝试在 PHP 文件中进行肥皂调用来轻松尝试此操作。
这是完整的代码:
public static function validateTIN($tin) {
// Stream context due to certificate problems
$streamContext = stream_context_create(array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
));
// Create our soap client
$client = new SoapClient('https://ec.europa.eu/taxation_customs/tin/checkTinService.wsdl', array(
'exceptions' => 0,
'trace' => 1,
'connection_timeout' => 1800,
'stream_context' => $streamContext
));
dd($client->__getFunctions());
return true;
}
【问题讨论】:
-
您仍然收到此错误吗?我刚刚尝试过你的源代码,它没有任何问题。
-
这在哪个版本的 PHP 中失败了?
标签: php web-services soap wsdl