2016-09-14 149 views
1

我正在灯堆栈上从头开始构建我的第一个项目。我决定尝试一下slim api框架。下面你可以看到我开始为我的API创建一个辅助函数。但是我得到这个未定义常量CURLOPT_GET - 假定'CURLOPT_GET'

错误:未定义的常量CURLOPT_GET - 假设 'CURLOPT_GET'

,然后这个

错误:curl_setopt()预计参数2长,串给出

// Main Gospel Blocks API Call Function 
Function gbCall($gbRoute) { 
     // JSON Headers 
    $gblCallHeaders[] = "Content-Type: application/json;charset=utf-8"; 

    // Call the API 
    $gblCall = curl_init(); 
    curl_setopt($gblCall, CURLOPT_URL, $GLOBALS['gbApiUrl'] . $gbRoute); 
    curl_setopt($gblCall, CURLOPT_GET, TRUE); 
    curl_setopt($gblCall, CURLOPT_RETURNTRANSFER, TRUE); 
    curl_setopt($gblCall, CURLOPT_HTTPHEADER, $gblCallHeaders); 

    // Get the response 
    $response = curl_exec($gblCall); 

    // Close cURL connection 
    curl_close($gblCall); 

    // Decode the response (Transform it to an Array) 
    $response = json_decode($response, true); 

    // Return response 
    return $response; 
} 

我打的api只是json编码的对象,不太清楚为什么这不返回json ...

回答

0

有一个在选项卷曲没有像CURLOPT_GET。这就是这个错误发生的原因。看到

options

0

phpxxx-curl没有安装在你的机器

0
For the GET Request in the Curl 



    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL, "URL"); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET"); 

    $headers = array(); 
    $headers[] = "Key: Value"; 
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); 

    $result = curl_exec($ch); 
    if (curl_errno($ch)) { 
     echo 'Error:' . curl_error($ch); 
    } 

    curl_close ($ch);