I'm using the code below to query an api however I'm not seeing any output. The header is returned however I also get an error - "An error has occurred:" with nothing else - not very helpful to say the least. Does anyone know what I'm doing wrong here? (NB I've had to remove the user details for obvious reasons)
//Required Call Information;
$username = "xxxxxxxxxxxxx";
$password = "xxxxxxxxxxxxxxxxxxxxxxxxxx";
$remote_url = 'https://xxxxxxxxxxxxx.com/xx.json';
// init the resource
$ch = curl_init();
//Header Information;
$headr = array();
$headr[] = "Authorization: Basic " . base64_encode("$username:$password");
$headr[] = "X-Page:" . $pages;
// set curl options
curl_setopt($ch, CURLOPT_URL,$remote_url);
curl_setopt($ch, CURLOPT_HTTPHEADER,$headr);
curl_setopt($ch, CURLOPT_HEADER, true);
// execute
$output = curl_exec($ch);
// echo
echo $output;
// echo
print $output;
// free
curl_close($ch);
// check status of server being called vis crul
var_dump(curl_getinfo($ch));
//if error
if (!curl_exec($ch)) {
// if curl_exec() returned false and thus failed
echo 'An error has occurred: ' . curl_error($ch);
}
else {
echo 'everything was successful';
}
CURLOPT_RETURNTRANSFERopt forcurl_exec()to return the result.if ( ! curl_exec(...) ), you're doing another call to the URL. Better useif ( $output === FALSE ).