doutui839638 2014-02-18 17:28
浏览 192
已采纳

SOAP-ERROR:解析WSDL:无法加载 - 但适用于WAMP

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 is enabled

Error

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"

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;

Error

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

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
  • 写回答

6条回答 默认 最新

  • dongzai5181 2014-02-23 19:02
    关注

    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();
    }
    

    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.

    To verify this, try the following on your linux host:

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

    this IPv6 request fails.

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

    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
    

    both these IPv4 request succeeds.

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(5条)

报告相同问题?

悬赏问题

  • ¥15 分析下图所示同步时序逻辑电路的逻辑功能。
  • ¥15 halcon联合c#遇到了问题不能解决
  • ¥15 xshell无法连接提示ssh服务器拒绝密码
  • ¥15 AT89C52单片机C语言关于串口通信的位操作
  • ¥20 需要步骤截图(标签-服务器|关键词-map)
  • ¥50 gki vendor hook
  • ¥15 灰狼算法和蚁群算法如何结合
  • ¥15 这是一个利用ESP32自带按键和LED控制的录像代码,编译过程出现问题,请解决并且指出错误,指导如何处理 ,协助完成代码并上传代码
  • ¥20 stm32f103,hal库 hal_usart_receive函数接收不到数据。
  • ¥20 求结果和代码,sas利用OPTEX程序和D-efficiency生成正交集