問題描述
這在我的 WAMP 服務器上工作正常,但在 linux 主服務器上不起作用!?
This works fine on my WAMP server, but doesn't work on the linux master server!?
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();
}
我在這里錯過了什么?!:(
What am I missing here?! :(
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 返回錯誤
Call the URL from PHP
Calling the URL from PHP returns error
$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 響應
Call the URL from command line
Calling the URL from the linux command line HTTP 200
is returned with a XML response
curl http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl
推薦答案
對于某些版本的 php,SoapClient 不發送 http 用戶代理信息.與本地 WAMP 相比,您在服務器上有哪些 php 版本?
For some versions of php, the SoapClient does not send http user agent information. What php versions do you have on the server vs your local WAMP?
嘗試使用上下文流顯式設置用戶代理,如下所示:
Try to set the user agent explicitly, using a context stream as follows:
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();
}
編輯
實際上,您使用的網絡服務似乎存在一些問題.基于 IPv6 的 HTTP 和缺少 HTTP 用戶代理字符串的組合似乎給 Web 服務帶來了問題.
Edit
It actually seems to be some issues with the web service you are using. The combination of HTTP over IPv6, and missing HTTP User Agent string, seems to give the web service problems.
要驗證這一點,請在您的 linux 主機上嘗試以下操作:
To verify this, try the following on your linux host:
curl -A '' -6 http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl
此 IPv6 請求失敗.
this IPv6 request fails.
curl -A 'cURL User Agent' -6 http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl
此 IPv6 請求成功.
this IPv6 request succeeds.
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 請求都成功.
both these IPv4 request succeeds.
有趣的案例 :) 我猜您的 linux 主機將 ec.europa.eu 解析為其 IPv6 地址,并且您的 SoapClient 版本默認沒有添加用戶代理字符串.
Interesting case :) I guess your linux host resolves ec.europa.eu to its IPv6 address, and that your version of SoapClient did not add a user agent string by default.
這篇關于SOAP-ERROR:解析 WSDL:無法加載 - 但適用于 WAMP的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!