未定义常量CURLOPT_GET -假设'


undefined constant CURLOPT_GET - assumed 'CURLOPT_GET'

我正在从头开始构建我的第一个项目。我决定尝试一下精简的api框架。下面你可以看到我开始为我的api构建一个辅助函数。然而,我得到这个

错误:undefined constant 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…

尝试使用CURLOPT_HTTPGET,尽管我不确定它是否符合您的目的。

更多细节请点击此处

当您的机器没有安装phpxxx-curl时发生

cURL的选项中没有CURLOPT_GET,这就是发生错误的原因。看看CURL选项

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);