我正在尝试使用 Curl 登录 Tumblr,以下 curl 帖子登录成功,但它重定向到 mydomain.com/dashboard 而不是 tumblr.com/dashboard,我如何重定向到 tumblr.com/dashboard?或者我应该使用 GET curl 到 tumblr.com/dashboard 使用 cookie 吗?
$url = 'https://www.tumblr.com/login';
$fields = array(
'user[email]'=> $email,
'user[password]'=>$pass,
'tumblelog[name]'=> '',
'user[age]'=> '',
'recaptcha_public_key'=> urlencode($key),
'recaptcha_response_field'=> '',
'hk'=> urlencode($hk[1]),
'http_referer' => 'https%3A%2F%2Fwww.tumblr.com%2Flogin'
);
//url-ify the data for the POST
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string, '&');
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch,CURLOPT_COOKIEJAR, "cookie.txt");
curl_setopt($ch,CURLOPT_COOKIEFILE, "cookie.txt");
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
$result = curl_exec($ch);
var_dump($result);
Ps : 我在 cookie.txt 中成功存储了 cookie,我可以使用该 cookie 来获取 tumblr.com/dashboard 的内容吗