欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

php模拟登录目标网站,为何302没有跟随跳转.cookie已经获得.求解惑.

程序员文章站 2022-05-04 12:12:07
...
跳转phpcurlcookie
  $user,'Password'=> $pass,'RedirectAfterLoginUrl'=>'https://www.mql5.com/zh','RememberMe'=>false,);//step 1//获取一个cookie$ch = curl_init();curl_setopt($ch, CURLOPT_URL, $url);curl_setopt($ch, CURLOPT_HEADER, 0);curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);$content1 = curl_exec($ch);curl_close($ch);//step 2//post 数据;$ch = curl_init();curl_setopt($ch, CURLOPT_URL, $url);curl_setopt($ch, CURLOPT_HEADER, 0);curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);// 从证书中检查SSL加密算法是否存在curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 120);// 自动跟随跳转curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);curl_setopt($ch, CURLOPT_AUTOREFERER, 1);curl_setopt($ch, CURLOPT_POST, count($fields));curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($fields_post));$result= curl_exec($ch);curl_close($ch);