PHP CURL - 页面重定向

时间:2014-01-06 13:10:55

标签: php curl

我正在尝试阅读以下页面的HTML:

$curl_handle=curl_init();
curl_setopt($curl_handle, CURLOPT_URL,"http://www.mouser.com/ProjectManager/ProjectDetail.aspx?AccessID=795ce57bad");
curl_setopt($curl_handle, CURLOPT_HEADER, true);
curl_setopt($curl_handle, CURLOPT_COOKIEFILE, "cookie.txt");
curl_setopt($curl_handle, CURLOPT_COOKIEJAR, "cookie.txt");
curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_handle, CURLOPT_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($curl_handle, CURLOPT_FOLLOWLOCATION, true);
$html = curl_exec($curl_handle);
curl_close($curl_handle);

echo $html;

但结果总是一样的:

HTTP/1.1 302 Moved Temporarily
Date: Mon, 06 Jan 2014 13:03:18 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 191
Connection: keep-alive
Cache-Control: private
Location: http://fr.mouser.com/ProjectManager/ProjectDetail.aspx?AccessID=795ce57bad
Access-Control-Allow-Origin: *
Access-Control-Allow-Origin: *
Set-Cookie: ASP.NET_SessionId=tzhb5d1nuscx1a54jw4ezhh2; domain=.mouser.com; path=/; HttpOnly
Set-Cookie: CARTCOOKIEUUID=d7f34cf4-23c7-48ec-847a-70ac0eeddb4d; domain=.mouser.com; expires=Tue, 06-Jan-2015 13:03:18 GMT; path=/
Set-Cookie: preferences=ps=fr; domain=.mouser.com; path=/

<html><head><title>Object moved</title><script type="text/javascript">
//<![CDATA[
try{if (!window.CloudFlare) {var CloudFlare=[{verbose:0,p:0,byc:0,owlid:"cf",bag2:1,mirage2:0,oracle:0,paths:{cloudflare:"/cdn-cgi/nexp/dokv=964071af18/"},atok:"5a38215b5511f581b1f5cf0315deacae",petok:"e9b3a4cf54c42b8094a77ff0389db61fb56dcb6b-1389013393-1800",zone:"josescxavier.com",rocket:"0",apps:{"vig_key":{"sid":"6890506acb4f07b174d0f59c693ffa44"}}}];var a=document.createElement("script"),b=document.getElementsByTagName("script")[0];a.async=!0;a.src="//ajax.cloudflare.com/cdn-cgi/nexp/dokv=5e636c62d6/cloudflare.min.js";b.parentNode.insertBefore(a,b);}}catch(e){};
//]]>
</script>
</head><body>
<h2>Object moved to <a href="http://fr.mouser.com/ProjectManager/ProjectDetail.aspx?AccessID=795ce57bad">here</a>.</h2>
</body></html>
{"error":"Your link doesn't look like a Mouser cart!"}

如何重定向?或者至少如何检查http响应,如果是HTTP 302,我会为新链接执行另一个curl_exec。

谢谢

0 个答案:

没有答案