項目中有個需求,要求能夠導入MSN及QQ聯系人。MSN的好說,有開源的jmsn及其它眾多開源組件。可是QQ仍然是我行我素,至今也不開放API。雖然網上查到有lumaqq這樣的開源
協議,可我Down下了折騰了半天,QQ都沒有登錄上去,好啦,我承認自己資質愚鈍。時間緊迫,來不及仔細研究了,於是打起了QQ郵箱的主意~~
既然通過浏覽器可以登錄QQ郵箱,查看聯系人,那麼我們同樣可以用程序模擬浏覽器登錄獲取聯系人。嗯,聽起來不錯,試試吧。
登錄請求:
Http代碼
POST /cgi-bin/login?sid=0,2,zh_CN HTTP/1.1
Host: m126.mail.qq.com
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; zh-CN; rv:1.9.0.13) Gecko/2009073022 Firefox/3.0.13 (.NET CLR 3.5.30729)
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: zh-cn,zh;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: gb2312,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Referer: http://mail.qq.com/cgi-bin/loginpage
Cookie: verifysession=c6c09b326c4dac79b727c7e6e1069238e9bfe9ae6e7943e740a535af7cc57bddeacf1b617a15a912; pvid=5429125866; flv=10.0 r22; };
r_cookie=9828306541
Content-Type: application/x-www-form-urlencoded
Content-Length: 371
sid=0%2C2%2Czh_CN&firstlogin=false&starttime=1251436516205&redirecturl=&f=html&p=UyoLX7JYspcnU9wCUK7qBA2Xjwo%2FO52FldnJnRABCnNLXI1ndwR8%2BQaepkT%
2FIcKHxMshWv4SjrxgvRtA%2B1eHAookTXzcia%2FhP5QrRlGyNoqzVCi1X%2FsJwb4SmjPZRwV%2B7WeskUwClUfeNv%2BmCq0ygoNzi9UnIVeI7lYzgqXnxZE%
3D&delegate_url=&s=&ts=1251436494&from=&uin=XXXXXXXX&aliastype=%40qq.com&pp=000000000&verifycode=qmpb
響應:
Http代碼
HTTP/1.1 200 OK
Connection: close
Date: Fri, 28 Aug 2009 05:15:18 GMT
Content-Type: text/html; charset=gbk
Set-Cookie:tinfo=1251436518.0550; Domain=mail.qq.com; Path=/
Set-Cookie:wimrefreshrun=; Domain=mail.qq.com; Path=/
Set-Cookie:autologin=EXPIRED; Domain=mail.qq.com; Path=/; Expires=Fri, 28-Aug-2009 05:17:18 GMT
Set-Cookie:sid=; Domain=mail.qq.com; Path=/; Expires=Wed, 31-Dec-1969 23:59:59 GMT
Set-Cookie:sid=6449e26f4adc402ac5c80e08bec3ca6c; Domain=mail.qq.com; Path=/
Set-Cookie:username=; Domain=mail.qq.com; Path=/; Expires=Wed, 31-Dec-1969 23:59:59 GMT
Set-Cookie:username=XXXXXXXX; Domain=mail.qq.com; Path=/
Set-Cookie:[email protected]; Domain=mail.qq.com; Path=/
Set-Cookie:qqmail_sid=6449e26f4adc402ac5c80e08bec3ca6c; Domain=qq.com; Path=/
Set-Cookie:qqmail_username=XXXXXXXX; Domain=qq.com; Path=/
Set-Cookie:qqmail_domain=http://m126.mail.qq.com; Domain=qq.com; Path=/
Set-Cookie:qqmail_key=1_de7d3652ab10a1616175bf2aab152fb7010b0d06020602060309; Domain=qq.com; Path=/
Set-Cookie:CCSHOW=0000; Domain=mail.qq.com; Path=/; Expires=Sun, 28-Oct-2012 15:01:58 GMT
Set-Cookie:noteorg=; Domain=mail.qq.com; Path=/; Expires=Sun, 28-Oct-2012 15:01:58 GMT
Set-Cookie:foxacc=0; Domain=mail.qq.com; Path=/; Expires=Sun, 28-Oct-2012 15:01:58 GMT
Set-Cookie:edition=4m126.mail.qq.com; Domain=mail.qq.com; Path=/; Expires=Sun, 28-Oct-2012 15:01:58 GMT
Content-Encoding: gzip
Content-Length: 356