I'm trying to work out why a call to a web service isn't returning the results I need.
Using CURL for Linux with
curl -i -H "Accept: application/json" "https://www.thisapi.com/stuff/?status=something" > myfile.txt
I get the correct results, an object starting: {"object_count": 4, ...
Using PHP with libcurl and
$curl = curl_init();
$hdr[] = 'Content-type: application/json';
$hdr[] = 'Accept: application/json';
curl_setopt($curl, CURLOPT_HTTPHEADER, $hdr);
$url = 'https://www.thisapi.com/stuff/?status=something';
curl_setopt($curl, CURLOPT_URL, $url);
//return the data
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$results = curl_exec($curl);
Ignores the URL variable "status" and I get {"object_count": 8 ...
Can anyone help me to work out in which ways these two requests are not equivalent and therefore why they are not returning the same results?
In the second case you have an additional header you are sending - Content-type: application/json
. Perhaps this is causing the API endpoint to respond differently, ignoring the parameter in the URL, as it is expecting something in JSON format.