我正在使用下面的代码来查询api,但是我没有看到任何输出。返回标题,但是我也收到一个错误 - "发生了错误:"没有其他东西 - 至少可以说不是很有帮助。有谁知道我在这里做错了什么?(注意,由于显而易见的原因,我不得不删除用户详细信息)
//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';
}
添加RETURN_TRANSFER curl opt将在调用$output = curl_exec($ch);
时返回数据而不是布尔值。
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
添加以下 curl 选项,看看你得到什么:
curl_setopt($ch, CURLOPT_VERBOSE, true);