已经发布了一个类似的问题,但我找不到那里的解决方案 Curl error Could not resolve host: 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);
?>
当我在浏览器中粘贴相同的地址时,我可以访问该网页。但是当我运行此脚本时,我收到错误消息。谁能帮帮我吗。 感谢
答案 0 :(得分:3)
删除urlencode
来电。
答案 1 :(得分:3)
删除它应该是urlencode($url)
:
$ch = curl_init($url);
答案 2 :(得分:1)
好。
如果您通过实例化urlencode()
- var删除$ch
,那么就可以了。 urlencode()
在这里肯定是错误的。
不可强>
$ch = curl_init($url);
<强>为:强>
$ch = curl_init(urlencode($url));
答案 3 :(得分:1)
$ch = curl_init($url);
而不是
$ch = curl_init(urlencode($url));