php - curl 函数返回协议(protocol) http 在 libcurl 中不受支持或禁用

标签 php http curl

我遇到了这个函数的问题:

function curl_function($uri) 
{    
    $ch = curl_init($uri);
    $timeout = 30; //set to zero for no timeout
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
    curl_setopt($ch, CURLOPT_USERAGENT, 'mycoreg');
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
    $file_contents = curl_exec($ch);
    $errornum      = curl_errno($ch);
    $info          = curl_getinfo($ch);
    $status        = (int) $info['http_code'];
    if ($errornum !== 0) {
        echo 'Error: ', curl_error($ch);
        $file_contents = NULL;
    }
    curl_close($ch);

    return $file_contents;
}

它给出的错误是

"http protocol is not supported or disabled".

请帮助。 谢谢。

最佳答案

调试打印您的 URL 并确保它不包含无关字符。

在我的例子中,引用了我在 php curl 中使用的 URL。引用不是由 curl 错误处理打印的,因此错误相当困惑且难以追踪。

您可以使用以下代码生成此错误:

// wrong
$uri = "'". "http://www.google.com/" . "'"; // quoted string
curl_setopt($ch, CURLOPT_URL, $url);

现在尝试使用正确的 URL 格式...

// right
$uri = "http://www.google.com/"; // correct format URL
curl_setopt($ch, CURLOPT_URL, $url);

关于php - curl 函数返回协议(protocol) http 在 libcurl 中不受支持或禁用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33035645/

相关文章:

php - 如何正确存储注册用户和大会其他参与者所需的信息? (方案 1 有效,但方案 2 和 3 无效)

php - 1M条记录时优化MySQL数据库select语句 : store old data separately?

ajax - 来自带有 AJAX 的页面的神秘隐藏 TCP 连接

java - HttpURLConnection 收到 405 但服务已完成

php - 如何在 mysql - php combo 的输出中干净地更改小数点分隔符

php - 安卓/PHP : Display “Data successfully save” after save input data from android to MySQL

python - 如何使用scrapy抓取具有多个页面的网站

php - 使用 cURL 上传多个文件

c++ - "failed writing body & data"libcurl C++

rest - 如何从服务器访问 JIRA