php - Localhost URL 在浏览器中有效,但对于 PHP curl_exec 返回 bool(false)

标签 php curl

我有以下 PHP 代码:

$curl = curl_init();
curl_setopt ($curl, CURLOPT_URL, $URL);
curl_setopt ($curl, CURLOPT_RETURNTRANSFER, true);
$html = curl_exec ($curl);

echo $html;

结果如下:

即使浏览器可以显示 http://localhost/index.html没问题。 我在本地主机上运行 xampp apache 服务器。

我不知道问题出在哪里。任何帮助将不胜感激。

最佳答案

您应该确保您的 Apache 监听正确的接口(interface)。我曾经在 Vist 机器上遇到过这个问题:Apache (XAMP) 仅在 IPv4 上监听,但在 Vista 上“localhost”默认解析为 IPv6 地址。

要禁用 IPv6 地址,请编辑 %system32%\drivers\etc\hosts 文件并删除::1 行。

关于php - Localhost URL 在浏览器中有效,但对于 PHP curl_exec 返回 bool(false),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4604845/

相关文章:

php - Json 数据错误 : Laravel 5. 1

php - 遇到 Ubuntu LAMP 堆栈问题

rest - 使用 cURL 的 HTTP GET 给出 SSL 错误

post - curl 发布数据和文件当代

curl: (35) SSL 连接错误,NSS 错误 -5938

php - htaccess 重写后 "Unexpected token ' > '"第 1 行(中断 css 和图像)

php - 在 PHP 中打印 MongoDB 对象 _id

php - 进入Fk表更新记录

javascript - curl机制,在expressjs代码里面

ios - 将 CURL 转换为 Swift 以在 Alamofire 中使用