Home > Backend Development > PHP Tutorial > Why does 'SOAP-ERROR: Parsing WSDL: Couldn't Load from 'http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl'' occur on a Linux server when the script works on WAMP?

Why does 'SOAP-ERROR: Parsing WSDL: Couldn't Load from 'http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl'' occur on a Linux server when the script works on WAMP?

Susan Sarandon
Release: 2024-11-13 12:46:02
Original
508 people have browsed it

Why does

SOAP-ERROR: Parsing WSDL: Couldn't Load from "http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl"

When attempting to use a SoapClient on a Linux master server, users may encounter the error message "SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl'." This issue arises despite the script functioning correctly on a WAMP server.

To address this issue, it is recommended to explore potential differences in PHP versions between the server and the WAMP environment. Older PHP versions may lack the necessary functionality to send a User Agent string with SoapClient requests.

If this is the case, explicitly specifying a User Agent string can resolve the issue. This can be achieved by using a stream context, as illustrated below:

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

Alternatively, it has been observed that this issue can arise due to a combination of HTTP over IPv6 and the absence of a User Agent string in the request. The web service involved may exhibit issues under these conditions.

To confirm this, execute the following commands on the Linux host:

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

If the IPv6 request fails, try adding a User Agent string:

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

Both IPv4 requests should succeed:

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
Copy after login

If these observations hold true, it is likely that the Linux host is resolving the URL to its IPv6 address and the SoapClient version on the server is not appending a User Agent string by default.

The above is the detailed content of Why does 'SOAP-ERROR: Parsing WSDL: Couldn't Load from 'http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl'' occur on a Linux server when the script works on WAMP?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template