PHP curl获取多维数组
我正在尝试使用gitlab API获取问题列表。测试URL时,响应是正确的,但是在我的php代码中没有执行curl。我想这是因为多维数组。但是你怎么解决这个问题呢?以下是我的功能:PHP curl获取多维数组,php,curl,get,Php,Curl,Get,我正在尝试使用gitlab API获取问题列表。测试URL时,响应是正确的,但是在我的php代码中没有执行curl。我想这是因为多维数组。但是你怎么解决这个问题呢?以下是我的功能: function getissues_list () { $url = MAIN_URL."/issues"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETU
function getissues_list () {
$url = MAIN_URL."/issues";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPGET , true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $this->token);
$response = curl_exec($ch);
if (!curl_exec($ch)) {
echo ($this->exception_message);
} else{
return $response;
curl_close($ch);
}
}
谢谢 请分享
print\r($response)的回复代码>和打印(卷曲错误($ch))代码>无法解析主机:MAIN\u URL//无法初始化curl会话!只需确保您的MAIN\u URL./issues“
正确。由于某种原因,您实际上无法连接常量和第二部分…您可以执行打印(MAIN\u URL)
并在if语句前一行共享结果,结果为bool(false)。否则它只执行if语句中的代码。忘了提到这段代码与另一个返回单个数组的url一起工作。。。
function getissues_list () {
global MAIN_URL; // Is this accessible in this function?
$url = MAIN_URL."/issues";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPGET , true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $this->token);
$response = curl_exec($ch);
var_dump($response);// ADD THIS LINE TO DEBUG!!!!!!!!
if (!curl_exec($ch)) {
echo ($this->exception_message);
} else{
return $response;
curl_close($ch);
}
}