Skip to content
Advertisement

cURL to get XML response from an API not working

When I try the url for API endpoint directly in browser, it works and returns XML data, but when I try with cURL, it returns 01 - Unavailable service error, so the issue must be with my cURL code.

PHP:

JavaScript

Direct URL that works and returns XML data:

JavaScript

Advertisement

Answer

Rather than trying to send the url parameters within the headers ( as noted by @CBroe earlier ) you need to create the url with querystring before calling curl_init

JavaScript

Which then unsurprisingly yields:

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement