cURL - 当我知道我应该得到302时,为什么我会得到200 OK?

时间:2012-04-21 23:37:18

标签: php curl

我正在我的网站上测试cURL,以更好地学习cURL 我注意到,即使我正确设置了参数,当我得到302并重定向到login.php时,我得到200 OK ......

这可能与cookie有关吗?

$cookiefilename="c://xampp/htdocs/Mysite/cookie.txt";
$curl = curl_init();
$theUrl = "http://localhost/Mysite/index.php";
curl_setopt ($curl, CURLOPT_URL, $theUrl);
curl_setopt($curl, CURLOPT_TIMEOUT, 10);
curl_setopt ($curl, CURLOPT_USERAGENT, "User-Agent  Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0; MAAU)");

curl_setopt($curl, CURLOPT_COOKIESESSION, true);
curl_setopt($curl, CURLOPT_COOKIEFILE, $cookiefilename);
curl_setopt($curl, CURLOPT_COOKIEJAR, $cookiefilename); 
curl_setopt($curl, CURLOPT_FRESH_CONNECT , 1);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION  ,0);
curl_setopt($curl, CURLOPT_HEADER      ,1);  
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($curl, CURLOPT_POST      ,1);
$fields_string = "username=*******&password=******&submit=login";
curl_setopt($curl, CURLOPT_POSTFIELDS, $fields_string);
curl_setopt($curl, CURLOPT_HTTPGET , 1);
$html=curl_exec($curl);
curl_close($curl);

0 个答案:

没有答案