SOAP错误:解析WSDL:无法从中加载-但可在WAMP上使用 [英] SOAP-ERROR: Parsing WSDL: Couldn't load from - but works on WAMP

查看:316
本文介绍了SOAP错误:解析WSDL:无法从中加载-但可在WAMP上使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这在我的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命令行HTTP 200调用URL随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();
}

编辑

您使用的Web服务实际上似乎存在一些问题.通过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请求失败.

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请求都成功.

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错误:解析WSDL:无法从中加载-但可在WAMP上使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆