使用未定义的常量CURLOPT_POST - 假设为'CURLOPT_POST'

xyl*_*lar 8 php apache curl wamp kohana

我正在通过Kohana 3.2发出cURL请求但是当它尝试访问CURLOPT_POST常量时我收到以下错误:

Use of undefined constant CURLOPT_POST - assumed 'CURLOPT_POST'
Run Code Online (Sandbox Code Playgroud)

来自Kohana 3.2 system/classes/kohana/request/client/curl.php

public function _set_curl_request_method(Request $request, array $options)
{
    switch ($request->method()) {
        case Request::POST:
            $options[CURLOPT_POST] = TRUE;
            break;
        case Request::PUT:
            $options[CURLOPT_PUT] = TRUE;
            break;
        default:
            $options[CURLOPT_CUSTOMREQUEST] = $request->method();
            break;
    }
    return $options;
}
Run Code Online (Sandbox Code Playgroud)

我的应用代码:

$request = Request::factory($uri);
$request->query('key', $key);
$request->post($params);
$request->method(Request::POST);

// fails here
$response = $request->execute();
Run Code Online (Sandbox Code Playgroud)

我测试了curl作为扩展使用时的活动:

if (in_array  ('curl', get_loaded_extensions()))
{
    echo '1';
}
else
{
    echo '0';
}
Run Code Online (Sandbox Code Playgroud)

这里有什么问题?我使用的是Windows 7,PHP 5.4.12和Apache 2.4.

小智 9

首先,让我们检查你的服务器上是否安装了php-curl

aptitude search php-curl
Run Code Online (Sandbox Code Playgroud)

要么 aptitude search php5.6-curl

如果还没有安装,让我们安装它

sudo apt-get install php5.6-curl
Run Code Online (Sandbox Code Playgroud)


xyl*_*lar 5

我注意到extension=php_curl.dll被注释掉C:\wamp\bin\php\php5.4.12\php.ini但是活跃的通过C:\wamp\bin\apache\Apache2.4.4\bin\php.ini.

我发现在C:\wamp\bin\php\php5.4.12\php.ini修复我的问题时取消注释该行.