CURL을 사용하여 간단한 트위터 로그인 스크립트를 디자인하고 있으며이를 실행하려고하면 POST로 보낼 때 로그인 양식이 GET으로 전송됩니다. 이로 인해 사용자 홈페이지의 헤더 만 브라우저에 표시됩니다.Curl : GET으로 변환하는 POST
모든 의견을 환영합니다.
<?php
function tw_connect($user, $pwd) {
$agent = "Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.9.2.16) Gecko/20110319 Firefox/3.6.16";
$ch = curl_init('http://www.twitter.com');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$c = curl_exec($ch);
curl_close($ch);
preg_match_all('#authenticity_token" type="hidden" value="(.*)"#U', $c, $g);
$g = $g[1][0];
$post = 'authenticity_token=' . trim($g[1]) . '&authenticity_token=' . trim($g[1]) .
'&return_to_ssl=false&redirect_after_login=&session' . urlencode("[username_or_email]") .
'=' . $user . '&' . urlencode("session[password]") . '=' . $pwd . '&commit=' . urlencode("Sign In");
$ch2 = curl_init('https://twitter.com/sessions');
curl_setopt($ch2, CURLOPT_USERAGENT, $agent);
curl_setopt($ch2, CURLOPT_REFERER, 'http://twitter.com/');
curl_setopt($ch2, CURLOPT_POST, TRUE);
curl_setopt($ch2, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch2, CURLOPT_COOKIEFILE, 'cookie.txt');
curl_setopt($ch2, CURLOPT_COOKIEJAR, 'cookie.txt');
curl_setopt($ch2, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch2, CURLOPT_HTTPHEADER, array('Expect:'));
curl_setopt($ch2, CURLOPT_COOKIESESSION, true);
curl_setopt($ch2, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch2, CURLOPT_RETURNTRANSFER, TRUE);
$v = curl_exec($ch2);
echo $v;
}
tw_connect('username','password');
?>
스크립트가 POST가 아닌 GET으로 데이터를 전송한다고 생각합니까? – SIFE
나는 파이어 폭스 용 피들러와 LiveHTTPHeader 애드온을 모두 확인했다. 둘 다 GET 요청으로 보여줍니다. – Dew
TRUE를 제거하고 1로 바꾸어보십시오. – SIFE