论坛首页 Java企业应用论坛

用java httpclient模拟登录 获取163邮箱联系人

浏览 11250 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2009-11-07   最后修改:2009-11-07
先用firebug 看一下 整个登录的过程 在模拟登录中要用到

1.登录通行证 请求:

http://reg.163.com/login.jsp?type=1&product=mail163&url=http://entry.mail.163.com/coremail/fcg/ntesdoor2?lightweight%3D1%26verifycookie%3D1%26language%3D-1%26style%3D-1&=163&=-1&=-1&=-1&password=xxxxxx&rmbUser=on&user=xxxaaa&username=xxxaaa%40163.com

Host: reg.163.com
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.1.4) Gecko/20091016 Firefox/3.5.4
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,zh;q=0.8,en;q=0.5,it;q=0.3
Accept-Encoding: gzip,deflate
Accept-Charset: GB2312,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Proxy-Connection: keep-alive
Referer: http://email.163.com/
Cookie: _ntes_nnid=1d78e768f023f744d5adf30f0de8e1ae,0; _ntes_nuid=1d78e768f023f744d5adf30f0de8e1ae; P_INFO=xxxaaa@163.com|1257230124|2|mail163|11&24&1257230124453; Province=0; City=0; SID=aa45d5e4-e6db-48bc-86df-d56b09650937; URSJESSIONID=aEptFGSVnmoh; mail_host=g1a123.mail.163.com; ntes_ucc=; NTES_UFC=6000000000000000100000000000000000000000000000000000000000000000

这里的参数比较关键,username password 不能错 废话:P

回复:
Server: nginx
Date: Tue, 03 Nov 2009 06:38:17 GMT
Content-Type: text/html; charset=UTF-8
Vary: Accept-Encoding
Cache-Control: max-age=0, no-cache
Expires: Tue, 03 Nov 2009 06:38:17 GMT, Thu, 01 Jan 1970 00:00:00 GMT
Pragma: No-cache
Transfer-Encoding: chunked
Proxy-Connection: Keep-Alive
Connection: Keep-Alive
Content-Encoding: gzip
Set-Cookie: NTES_SESS=.e0d39Wqa.98MKxaUX9gc3G3RFw5QhkQacLATBzT2at1m8ak6mnaFivjEK8dl5tzd.aLhXMuHnDAFycOhE7bavULbB1K8Dnqb; path=/; domain=.163.com; HttpOnly
S_INFO=1257230296|0|1&25##; path=/; domain=.163.com;
P_INFO=xxxaaa@163.com|1257230296|0|mail163|11&24&1257230296223|1|25; path=/; domain=.163.com; expires=Wed, 3-Nov-2010 06:38:16 GMT;

登录成功,得到cookie 这是第一步。

2.登录邮箱 请求:
http://entry.mail.163.com/coremail/fcg/ntesdoor2?lightweight=1&verifycookie=1&language=-1&style=-1&username=xxxaaa

Host: entry.mail.163.com
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.1.4) Gecko/20091016 Firefox/3.5.4
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,zh;q=0.8,en;q=0.5,it;q=0.3
Accept-Encoding: gzip,deflate
Accept-Charset: GB2312,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Proxy-Connection: keep-alive
Referer: http://entry.mail.163.com/coremail/fcg/ntesdoor2?funcid=getusrnewmsgcnt&fid=1&addSubFdrs=1&language=0&style=0&template=newmsgres_urs_2009.htm&username=xxxaaa@163.com
Cookie: _ntes_nnid=1d78e768f023f744d5adf30f0de8e1ae,0; _ntes_nuid=1d78e768f023f744d5adf30f0de8e1ae; logType=-1; nts_mail_user=xxxaaa; ntes_mail_noremember=true; P_INFO=xxxaaa@163.com|1257230296|0|mail163|11&24&1257230296223|1|25; MAIL163_SSN=xxxaaa; Province=0; City=0; ntes_mail_firstpage=normal; Coremail=fzaNaQaifaZaI%nCRnXVAwctcKNpaaPQwwLmSTDywXWVeY; mail_style=js3; mail_host=g1a123.mail.163.com; mail_uid=xxxaaa@163.com; wmsvr_domain=g1a123.mail.163.com; ntes_ucc=; NTES_UFC=6000000000010000100000000000000000000000000000000000000000000000; NTES_SESS=.e0d39Wqa.98MKxaUX9gc3G3RFw5QhkQacLATBzT2at1m8ak6mnaFivjEK8dl5tzd.aLhXMuHnDAFycOhE7bavULbB1K8Dnqb; S_INFO=1257230296|0|1&25##; ALLYESID4=00091103144038501830; ALLYESSESSION1=4aefd0667a846

回复:
Date: Tue, 03 Nov 2009 06:41:15 GMT
Server: Apache
Location: http://g2a17.mail.163.com/a/j/js3/main.jsp?sid=TAfEuCeeOPJzfLxxxxxxxGCcwoBKFypI
Content-Type: text/html; charset=iso-8859-1
Content-Length: 263
Proxy-Connection: Keep-Alive
Connection: Keep-Alive
Set-Cookie: Coremail=adHNJOGabkvaa%TAfEuCeeOPJzfLxxxxxxxGCcwoBKFypI; path=/; domain=mail.163.com

这是一个302Redirect 回复
注意URL里的sid:TAfEuCeeOPJzfLxxxxxxxGCcwoBKFypI 取得联系人列表就靠它了

3.获取所以联系人

http://g1a123.mail.163.com/a/s?sid=TAfEuCeeOPJzfLxxxxxxxGCcwoBKFypI&func=mbox:getAllFolders
返还的是一个Json 对象


http://www.benbenhai.cn/2009/11/03/【导入163通讯录】163邮箱的登录过程/
http://www.benbenhai.cn/2009/11/03/【导入163通讯录】用java-httpclient-模拟登录/
论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics