我遇到了这个函数的问题:
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/