总共三次请求:
第一次目的获取 nonce servertime pubkey rsakv pcid
第二次目的获取 ticket loginUrl
第三次目的获取 Cookie
1.将用户名先urlencode编码再Base64Encode编码
2.根据http://login.sina.com.cn/sso/prelogin.PHP?entry=weibo&callback=sinaSSOController.preloginCallBack&su=二次编码后的用户名&rsakt=mod&checkpin=1&client=ssologin.js(v1.4.5)&_=System.currentTimeMillis() url来构造HttpGet
3.添加请求头
- headers.put("Accept", "*/*");
- headers.put("Referer", "http://weibo.com/");
- headers.put("Accept-Language", "zh-cn");
- headers.put("User-Agent", "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; QQDownload 691)");
- headers.put("Host", "login.sina.com.cn");
- headers.put("Connection", "Keep-Alive");</span>
4.抛出Get请求后 能够从响应中获得nonce servertime pubkey rsakv pcid这几个值
5.根据url(http://login.sina.com.cn/sso/login.php?client=ssologin.js(v1.4.5))构造HttpPost请求
6.用户名二次编码 密码RSA加密(servertime+"\t"+nonce+"\n"+password)并转为16进制
7.向HttpPost请求中加header
- headers.put("Accept", "text/html, application/xhtml+xml, */*");
- headers.put("Referer", "http://login.sina.com.cn/member/my.php?entry=sso");
- headers.put("Accept-Language", "zh-cn");
- headers.put("User-Agent", "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0; BOIE9;ZHCN");
- headers.put("Host", "login.sina.com.cn");
- headers.put("Connection", "Keep-Alive");
- headers.put("Content-Type", "application/x-www-form-urlencoded");
- headers.put("Cache-Control", "no-cache");</span>
8.向HttpPost中添加参数
- params.put("encoding", "UTF-8");
- params.put("entry", "weibo");
- params.put("from", "");
- params.put("prelt", "112");
- params.put("gateway", "1");
- params.put("nonce", nonce);
- params.put("pwencode", "rsa2");
- params.put("returntype", "META");
- params.put("pagerefer", "");
- params.put("savestate", "7");
- params.put("servertime", servertime);
- params.put("rsakv", rsakv);
- params.put("service", "miniblog");
- params.put("sp", 二次编码后的用户名);
- params.put("ssosimplelogin", "1");
- params.put("su", 加密后的密码);
- params.put("url", "http://weibo.com/ajaxlogin.php?framelogin=1&callback=parent.sinaSSOController.feedBackUrlCallBack");
- params.put("useticket", "1");
- params.put("vsnf", "1");</span>
9.Post请求后从响应中获取ticket loginUrl
10.构造HttpGet(http://passport.weibo.com/wbsso/login?ticket=上一步获取的ticket&url=上一步获取的loginUrl&ssosavestate=1468932314&retcode=0)
11.抛出Get请求 这里要设置HttpGet不让他自动重定向
12.此时response中的Set-Cookie就是我们想要的Cookie了
http://download.csdn.NET/detail/onepiecehuiyu/8931417