您好我在使用以下代码获取网址数据但什么都没有
$url = "http://www.amazon.co.uk/dp/B002P44QH2";
$ch = curl_init();echo $url;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$page = curl_exec($ch);
print_r(curl_getinfo($ch));
curl_close($ch);
return $page;
当我执行print_r(curl_getinfo($ ch))时,它返回以下输出:
Array
(
[url] => http://www.amazon.co.uk/dp/B002P44QH2
[content_type] =>
[http_code] => 0
[header_size] => 0
[request_size] => 0
[filetime] => -1
[ssl_verify_result] => 0
[redirect_count] => 0
[total_time] => 0
[namelookup_time] => 0.10347
[connect_time] => 0
[pretransfer_time] => 0
[size_upload] => 0
[size_download] => 0
[speed_download] => 0
[speed_upload] => 0
[download_content_length] => 0
[upload_content_length] => 0
[starttransfer_time] => 0
[redirect_time] => 0
)
当我在终端中执行此操作时,它会出现以下错误
curl -I http://www.amazon.co.uk/dp/B002P44QH2
错误:
curl: (7) Failed to connect to 178.236.5.39: Network is unreachable
请帮助
答案 0 :(得分:1)
它是共享托管服务器,如果是,那么某些共享托管服务器不会允许curl请求 - 请查看此答案以获取更多信息https://stackoverflow.com/a/9953646/308251