gpt4 book ai didi

php - SOAP 错误 : Parsing WSDL: Couldn't load from - but works on WAMP

转载 作者:IT王子 更新时间:2023-10-28 23:55:42 27 4
gpt4 key购买 nike

这在我的 WAMP 服务器上工作正常,但在 linux 主服务器上不起作用!?

try{
$client = new SoapClient('http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl', ['trace' => true]);
$result = $client->checkVat([
'countryCode' => 'DK',
'vatNumber' => '47458714'
]);
print_r($result);
}
catch(Exception $e){
echo $e->getMessage();
}

我在这里错过了什么?! :(

启用 SOAP

错误

SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl' : failed to load external entity "http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl"/taxation_customs/vies/checkVatService.wsdl"

从 PHP 调用 URL

从 PHP 调用 URL 返回错误

$wsdl = file_get_contents('http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl');
echo $wsdl;

错误

Warning:  file_get_contents(http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl): failed to open stream: HTTP request failed! HTTP/1.0 503 Service Unavailable

从命令行调用 URL

从 linux 命令行调用 URL HTTP 200 返回 XML 响应

curl http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl

最佳答案

对于某些版本的 php,SoapClient 不发送 http 用户代理信息。与本地 WAMP 相比,您在服务器上有哪些 php 版本?

尝试使用上下文流显式设置用户代理,如下所示:

try {
$opts = array(
'http' => array(
'user_agent' => 'PHPSoapClient'
)
);
$context = stream_context_create($opts);

$wsdlUrl = 'http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl';
$soapClientOptions = array(
'stream_context' => $context,
'cache_wsdl' => WSDL_CACHE_NONE
);

$client = new SoapClient($wsdlUrl, $soapClientOptions);

$checkVatParameters = array(
'countryCode' => 'DK',
'vatNumber' => '47458714'
);

$result = $client->checkVat($checkVatParameters);
print_r($result);
}
catch(Exception $e) {
echo $e->getMessage();
}

编辑

实际上您使用的网络服务似乎存在一些问题。 HTTP over IPv6 和缺少 HTTP 用户代理字符串的组合似乎给 Web 服务带来了问题。

要验证这一点,请在您的 linux 主机上尝试以下操作:

curl  -A ''  -6 http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl

此 IPv6 请求失败。

curl  -A 'cURL User Agent'  -6 http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl

此 IPv6 请求成功。

curl  -A ''  -4 http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl
curl -A 'cURL User Agent' -4 http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl

这两个 IPv4 请求都成功。

有趣的案例 :) 我猜您的 linux 主机将 ec.europa.eu 解析为其 IPv6 地址,并且您的 SoapClient 版本默认没有添加用户代理字符串。

关于php - SOAP 错误 : Parsing WSDL: Couldn't load from - but works on WAMP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21861077/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com