【发布时间】:2012-09-06 05:10:18
【问题描述】:
我正在尝试以下代码,因为由于重定向,我无法使用 php file_get_contents,但这没有返回任何内容:
function file_get_contents_curl($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
$url = 'http://www1.macys.com/shop/product/michael-michael-kors-wallet-jet-set-monogram-ziparound-continental?ID=597522&CategoryID=26846&RVI=Splash_5';
$html = file_get_contents_curl($url);
echo "html is ".$html;
【问题讨论】:
-
你试过 curl_getinfo() 和 curl_error() 看看他们报告了什么?
标签: php curl file-get-contents