2011-08-24 3 views
1
나는 웹 사이트

PHP 컬 POST DATA [리디렉션 302 문제]

$postData = array("login" => "Prijava", "loginEmail" => "****@****.***", "password" => "*****t", "signonForwardAction" => "/press/cm/si.press.viasat.tv?cc=si&lc=si"); 

$URL = "http://si.press.viasat.tv/press/cm/1.167?cc=si&lc=si"; 

$connection = curl_init(); 
curl_setopt($connection, CURLOPT_URL, $URL); 
curl_setopt($connection, CURLOPT_POST, 1); 

curl_setopt($connection, CURLOPT_POSTFIELDS, $postData); 

curl_setopt($connection, CURLOPT_FOLLOWLOCATION, true); 

curl_setopt($connection, CURLOPT_REFERER, "http://si.press.viasat.tv"); 
curl_setopt($connection, CURLOPT_AUTOREFERER, true); 
curl_setopt($connection, CURLOPT_HEADER, true); 
curl_setopt($connection, CURLOPT_POSTREDIR, 2); 

curl_setopt($connection,CURLOPT_COOKIEJAR, "C:\@DEV\TextALG\cookie.txt"); 
curl_setopt($connection,CURLOPT_COOKIEFILE, "C:\@DEV\TextALG\cookie.txt"); 

curl_exec($connection); 



curl_close($connection); 

에 로그인하려면 다음 코드를 사용

문제 (방화범 발견) 후 사이트 URL로 리디렉션 로그인 즉 (응답 : 302). 그리고 그 결과로 나는 다시 로그인 스크린을 얻는다.

이 같은 쿠키를 얻을 :

# Netscape HTTP Cookie File 
# http://curl.haxx.se/rfc/cookie_spec.html 
# This file was generated by libcurl! Edit at your own risk. 

si.press.viasat.tv FALSE /press FALSE 0 JSESSIONID 00FC3DCA4CFD806CDEBE2CAA7E999463 

어떤 아이디어가?

+0

302 응답이없는 사이트에서는 정상적으로 작동합니다 .. –

+0

'curl_setopt ($ connection, CURLOPT_HEADER, false);로 시도했습니다. – diEcho

답변

0

내가 다른 논리 시도 옵션

CURLOPT_FOLLOWLOCATION => TRUE,  // follow redirects   
CURLOPT_MAXREDIRS  => 10,  // stop after 10 redirects 

Reference

2

아래에 추가하려고 (검색 논리와 지금은 작동한다!)

$ch = curl_init(); 
$randnum = rand(1,5000); 
curl_setopt($ch, CURLOPT_COOKIEJAR, "/tmp/cookiejar-$randnum"); 
curl_setopt($ch, CURLOPT_COOKIEFILE, "/tmp/cookiejar-$randnum"); 
curl_setopt($ch, 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($ch, CURLOPT_FOLLOWLOCATION, 1); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_POST, 0); 


curl_setopt($ch, CURLOPT_URL,$URL); 
$page = curl_exec($ch); 

preg_match("/action=\"(.*)\"/", $page, $action); 
preg_match("/signonForwardAction\" type=\"hidden\" value=\"(.*)\"/", $page, $signonFA); 

$action = $action[1]; 
$signonFA = $signonFA[1]; 
$postData['signonForwardAction'] = $signonFA; 


curl_setopt($ch, CURLOPT_URL,$URL.$action); 
curl_setopt($ch, CURLOPT_REFERER, $URL); 
curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type: application/x-www-form-urlencoded")); 
curl_setopt($ch, CURLOPT_POST, 1); 
curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($postData)); 
$page = curl_exec($ch); 

기본 아이디어는 현장에 도착하는 것입니다, 쿠키를 설정하고 데이터를 게시 (문자열이 배열이 아니어야합니다!) 사이트로 이동하고 ($ action으로 이동) 계속 사이트를 크롤링하십시오!