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