Heim  >  Artikel  >  Backend-Entwicklung  >  模拟登陆正方教务系统,重定向一直解决不了〉

模拟登陆正方教务系统,重定向一直解决不了〉

WBOY
WBOYOriginal
2016-06-20 12:38:071685Durchsuche

<?php$login_url='http://jwxt.nbut.cn/(gnqj51blynlz1k45ufftjgux)/default_ysdx.aspx';$user='11480010126';$password='tianyun';$RadioButtonList1='学生';$__VIEWSTATE='dDw1MjQ2ODMxNzY7Oz5PMj6WMeVIzgWyGp6TS4sLvnQtaA=='; $cookie_file = tempnam('./temp','cookie');$login_url = 'http://jwxt.nbut.cn/(gnqj51blynlz1k45ufftjgux)/default_ysdx.aspx';$post_fields = array($user,$password,$RadioButtonList1,$__VIEWSTATE);//传入参数$ch = curl_init($login_url);curl_setopt($ch, CURLOPT_HEADER, 0);//显示头部curl_setopt($ch, CURLOPT_POST, 1);//post传递$header[]='User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.116 Safari/537.36';curl_setopt($ch, CURLOPT_HTTPHEADER, $header);//模拟客户端curl_setopt($ch, CURLOPT_RETURNTRANSFER,0);//显示页面curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields);//post传递值curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);//存入cookiecurl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);//允许重定向curl_exec($ch);curl_close($ch);     $url='http://jwxt.nbut.cn/(gnqj51blynlz1k45ufftjgux)/xs_main.aspx?xh='.$user;$ch = curl_init($url);curl_setopt($ch, CURLOPT_HEADER, 0);curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);curl_setopt($ch, CURLOPT_POST, 1);$header[]='Referer:http://jwxt.nbut.cn/(gnqj51blynlz1k45ufftjgux)/default_ysdx.aspx';$header[]='User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.116 Safari/537.36';curl_setopt($ch, CURLOPT_HTTPHEADER, $header);curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);//读取cookieecho $contents;$contents = curl_exec($ch);curl_close($ch); ?>


回复讨论(解决方案)

在线等,拜托各位

返回 <script>alert('密码错误!!');</script>

这个网站没有使用 cookie 传递 sessionid 而是通过 url 传递的
所以你把这个写死是不行的:
http://jwxt.nbut.cn /(gnqj51blynlz1k45ufftjgux)/default_ysdx.aspx
而是应这样写

$url = 'http://jwxt.nbut.cn';$u = get_headers($url, 1);$login_url = 'http://jwxt.nbut.cn' . dirname($u['Location']) . '/default_ysdx.aspx';
另外提交的参数应是关联数组,而非下标数组
$post_fields = array(  'TextBox1' => $user = '11480010126',  'TextBox2' => 'tianyun',  'RadioButtonList1' => '学生',  '__VIEWSTATE' => 'dDw1MjQ2ODMxNzY7Oz5PMj6WMeVIzgWyGp6TS4sLvnQtaA==',  "Button1" => "  登录  ",);
注意:要使用 gbk 编码的

所以并不是重定向的问题,而是你根本就没有登录上去

用于现在返回的是 密码错误,所以无法再观察第二段 curl 的情况了

很多大学都用正方教务系统么?我们学校也是哎

2楼已经分析的很正确,我只作解释!
当输入网址http://jwxt.nbut.cn,服务端会重定向到一个网页,也就是在http://jwxt.nbut.cn后加上/随机串/default_ysdx.aspx,这个随机串存储到服务端的。所以你写死就是不正确的。
首先请求网址http://jwxt.nbut.cn。获取响应头中的Location,如图:


然后拼接你的url,再次访问http://jwxt.nbut.cn/Location/default_ysdx.aspx网址。这是一点。
2:查看源代码
提交的参数是关联数组,并非下表数组。
截部分图:




上面完成了!你就登录成功了。

我们学校也是这玩意==
但我用python写的时候怎么获取那个Location呢,谢谢

手动@二楼 @四楼

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn