/// <summary> /// 预登录得到所需的参数 /// </summary> private void GetParameter() { string url = "http://login.sina.com.cn/sso/prelogin.php?entry=weibo&callback=sinaSSOController.preloginCallBack&su=" + su + "&rsakt=mod&checkpin=1&client=ssologin.js(v1.4.18)"; string content = HttpHelper.Get(url, false); int pos; pos = content.IndexOf("servertime"); servertime = content.Substring(pos + 12, 10); pos = content.IndexOf("pcid"); pcid = content.Substring(pos + 7, 39); pos = content.IndexOf("nonce"); nonce = content.Substring(pos + 8, 6); pos = content.IndexOf("showpin"); showpin = content.Substring(pos + 9, 1); //showpin = "1"; //验证码测试 }
/// <summary> /// 得到cookie /// </summary> /// <param name="door"></param> /// <param name="retcode"></param> /// <returns></returns> private CookieContainer GetCookie(string door, out string retcode) { CookieContainer myCookieContainer = new CookieContainer(); string sp = GetSP(Password, servertime, nonce, PUBKEY);//得到加密后的密码 string postData = "entry=weibo&gateway=1&from=&savestate=7&useticket=1&pagerefer=&vsnf=1&su=" + su + "&service=miniblog&servertime=" + servertime + "&nonce=" + nonce + "&pwencode=rsa2&rsakv=" + RSAKV + "&sp=" + sp + "&sr=1366*768&encoding=UTF-8&prelt=104&url=http%3A%2F%2Fweibo.com%2Fajaxlogin.php%3Fframelogin%3D1%26callback%3Dparent.sinaSSOController.feedBackUrlCallBack&returntype=META"; if ((showpin == "1" || forcedpin) && door != null) { postData += "&pcid=" + pcid + "&door=" + door; } string content = HttpHelper.Post("http://login.sina.com.cn/sso/login.php?client=ssologin.js(v1.4.18)", postData); int pos = content.IndexOf("retcode="); retcode = content.Substring(pos + 8, 1); if (retcode == "0") { pos = content.IndexOf("location.replace"); string url = content.Substring(pos + 18, 285); //这里出错,浪费了我16小时检查出来,果然是太累了,妈蛋啊 //这里改为true,方便取Uid content = HttpHelper.Get(url, myCookieContainer, true); int a = content.IndexOf("uniqueid"); int b = content.IndexOf("userid"); Uid = content.Substring(a + 11, b - a - 14); //System.Windows.Forms.MessageBox.Show(Uid); return(myCookieContainer); } else { retcode = content.Substring(pos + 8, 4); return(null); } }
/// <summary> /// 使用登陆后得到的 cookie 进行GET (自动跳转) /// </summary> /// <param name="url"></param> /// <returns></returns> public string Get(string url) { return(HttpHelper.Get(url, myCookies, true)); }
private string Get(string url) { return(HttpHelper.Get(url, true)); }