[英]cURL error: Could not resolve host
A similar question has been posted at but i could not find the solution there Curl error Could not resolve host: saved_report.xml; 一个类似的问题已发布在,但我在那里找不到解决方案。Curl错误无法解析主机:saved_report.xml; No data record of requested type"
没有请求类型的数据记录”
<?php
$url="http://en.wikipedia.org/wiki/Pakistan";
$ch = curl_init(urlencode($url));
echo $ch;
// used to spoof that coming from a real browser so we don't get blocked by some sites
$useragent="Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1";
curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 4);
curl_setopt($ch, CURLOPT_TIMEOUT, 8);
curl_setopt($ch, CURLOPT_LOW_SPEED_TIME, 10);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$content = curl_exec($ch);
$info = curl_getinfo($ch);
if ($content === false || $info['http_code'] != 200) {
$content = "No cURL data returned for $url [". $info['http_code']. "]";
if (curl_error($ch))
$content .= "\n". curl_error($ch);
}
else {
// 'OK' status; format $output data if necessary here:
echo "...";
}
echo $content;
curl_close($ch);
?>
when i paste the same address in browser i am able to access the webpage. 当我在浏览器中粘贴相同的地址时,我可以访问该网页。 but when i run this script i get the error message.
但是当我运行此脚本时,我得到了错误消息。 Can anyone please help me.
谁能帮帮我吗。 Thanks
谢谢
删除urlencode
调用。
删除urlencode($url)
应该是:
$ch = curl_init($url);
Well. 好。
If you remove urlencode()
with instantiating your $ch
-var, you go just fine. 如果您通过实例化
$ch
-var删除urlencode()
,就可以了。 urlencode()
is definitely wrong here. urlencode()
在这里肯定是错误的。
Good: 好:
$ch = curl_init($url);
Bad: 坏:
$ch = curl_init(urlencode($url));
$ch = curl_init($url);
代替
$ch = curl_init(urlencode($url));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.