自动登录百度推广后台

这是前几天做的一个小项目,之所以拿它做例子是因为它很复杂。
网页分析工具:httpwatch,开发环境:vs2005 c#
首先,打开网页:http://www2.baidu.com,自动跳转到了http://cas.baidu.com/?tpl=www2&fromu=http%3A%2F%2Fwww2.baidu.com%2F
得到它的验证码地址: http://cas.baidu.com/?action=image&key=1252647747466 
验证码地址是根据前台js生成的
jCode
然后,取得提交地址:https://cas.baidu.com/?action=login  (注意:https是个难点,相当于换域了)
提交的字段:
appid    3
button2    登 录
charset    utf-8
entered_imagecode    ba27
entered_login    aaaaaa
entered_password    aaaaaa
fromu    http://www2.baidu.com/
登陆成功后,还没完,又经过两次重定位:
http://www2.baidu.com/?castk=878d9sf7f8ea78bd5d515 这个网页 Redirect to http://fengchao.baidu.com/indexAction.do?uid=1806516 (这里变换了域名)
http://fengchao.baidu.com/indexAction.do?uid=1806516 再次转向 Redirect to http://fengchao.baidu.com/indexAction.do?uid=1806516&userid=1806516
最后才是主页面:http://fengchao.baidu.com/indexAction.do?uid=1806516&userid=1806516

其实,对我们有用的就是 http://www2.baidu.com/?castk=878d9sf7f8ea78bd5d515 这个网页的cookie,有了这个,你才能在登录后做别的操作,否则登陆成功也没有意义。

下面是主程序:
Code

总之,做自动登录就要分析网页,熟练运用httpwatch,不要放过任何一个细节

posted on 2009-09-11 14:26  fatlity  阅读(27396)  评论(5)    收藏  举报

导航