CURL PHP - 缺少输出和未知错误

时间:2016-02-12 02:41:47

标签: php curl

我正在使用下面的代码查询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';
}

2 个答案:

答案 0 :(得分:2)

在调用$output = curl_exec($ch);时,添加RETURN_TRANSFER curl opt将返回数据而不是布尔值。

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

答案 1 :(得分:0)

添加以下curl opt并查看您的回复:

instructions["JA"]  = x86.AJHI
instructions["JAE"] = x86.AJCC
instructions["JB"]  = x86.AJCS
etc