我有以下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://www.google.com " 这样的$ URL
KO表示像" http://localhost/index.html " 这样的$ URL ,当我执行var_dump时返回bool(false)
即使浏览器可以显示http://localhost/index.html没有问题.我在localhost上运行xampp apache服务器.
我无法弄清楚问题是什么.任何帮助将非常感激.
您应该确保您的 Apache 侦听正确的接口。我曾经在 Vist 机器上遇到过这个问题:Apache (XAMP) 仅在 IPv4 上侦听,但在 Vista 上“localhost”默认解析为 IPv6 地址。
要禁用 IPv6 地址,请编辑%system32%\drivers\etc\hosts文件并删除 ::1 行。