php CURL - 错误代码:6 无法解析主机“http://www.yahoo.com” - XAMPP

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27185985/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 23:13:36  来源:igfitidea点击:

CURL - Error code: 6 Couldn't resolve host 'http://www.yahoo.com' - XAMPP

phpcurl

提问by user831098

Does anyone know what happen on the error as below when calling curl even call yahoo page:

有谁知道在调用 curl 甚至调用 yahoo 页面时会发生以下错误:

Error code 6 :Couldn't resolve host 'http://www.yahoo.com'; No data of requested type

错误代码 6:无法解析主机“ http://www.yahoo.com”;没有请求类型的数据

PHP

PHP

 $sendurl = "http://www.yahoo.com";
 $ch = curl_init($sendurl);                                                                     
 curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60);                                                                     
 $result = curl_exec($ch);

 if(!$result){
     echo $curl_errno($ch).":".curl_error($ch);
 }

回答by newman

This error mean that curl can't resolve host name.

此错误意味着 curl 无法解析主机名。

There is problem with DNS server on computer where you run this script.

运行此脚本的计算机上的 DNS 服务器存在问题。

If you run script on your local computer then check it just open www.yahoo.com in your browser.

如果您在本地计算机上运行脚本,请在浏览器中打开 www.yahoo.com 进行检查。

If you run script on remote server, then you should login to server by SHH and check ping www.yahoo.com. Or ask your hosting support team about this issue.

如果您在远程服务器上运行脚本,那么您应该通过 SHH 登录服务器并检查ping www.yahoo.com. 或者向您的托管支持团队询问此问题。

回答by gskema

I think you're missing options for allowing redirects and https. Check it in your browser -> you will get redirected to https URL.

我认为您缺少允许重定向和 https 的选项。在浏览器中检查 -> 您将被重定向到 https URL。

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, false);