Localhost URL在浏览器中工作,但返回PHP curl_exec的bool(false)

tuc*_*son 9 php curl

我有以下PHP代码:

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

echo $html;
Run Code Online (Sandbox Code Playgroud)

结果如下:

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

我无法弄清楚问题是什么.任何帮助将非常感激.

xrs*_*stf 4

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

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