|
楼主 |
发表于 2013-2-27 16:24:31
|
显示全部楼层
admin 发表于 2013-2-27 16:19
这个我真不清楚,我建议你网上SO一下有关百度登录的,这个应该有,我这里暂时没有资源 - GlbVars.cookie_baidu="";
- HttpWebRequest req = (HttpWebRequest)WebRequest.Create("https://passport.baidu.com/v2/api/?getapi&class=login&tpl=mn&tangram=true");
- HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
- GlbVars.cookie_baidu += ParseSetCookie(resp.Headers[HttpResponseHeader.SetCookie]);
- req.Abort();
- resp.Close();
-
- req = (HttpWebRequest)WebRequest.Create("https://passport.baidu.com/v2/api/?getapi&class=login&tpl=mn&tangram=true");
- req.Headers[HttpRequestHeader.Cookie] = GlbVars.cookie_baidu;
- resp = (HttpWebResponse)req.GetResponse();
- StreamReader sr = new StreamReader(resp.GetResponseStream());
- string token = "";
- while (sr.Peek() > -1)
- {
- string line = sr.ReadLine();
- if (line.Contains("token="))
- {
- token = GlbVars.CutBetween(line, "bdPass.api.params.login_token=\'", "\';");
- break;
- }
- }
- sr.Close();
- req.Abort();
- resp.Close();
复制代码 这是别人的部分代码。看他的意思是在这个流里会有。
我写了下面的,但是没有token=xxxx- item.URL = "https://passport.baidu.com/v2/api/?getapi&class=login&tpl=mn&tangram=true";
- item.Method = "GET";
- item.Encoding = "utf-8";
- item.ContentType = "application/x-www-form-urlencoded";
- item.UserAgent = "Mozilla/5.0 (Windows NT 5.1; rv:18.0) Gecko/20100101 Firefox/18.0";
- item.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
- item.Allowautoredirect = true;
- HttpResult result_t = http.GetHtml(item);
- HttpWebRequest req = (HttpWebRequest)WebRequest.Create("https://passport.baidu.com/v2/api/?getapi&class=login&tpl=mn&tangram=true");
- HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
- req.Headers[HttpRequestHeader.Cookie] = result_t.Cookie;
- resp = (HttpWebResponse)req.GetResponse();
- StreamReader sr = new StreamReader(resp.GetResponseStream());
- string token = "";
- while (sr.Peek() > -1)
- {
- string line = sr.ReadLine();
- if (line.Contains("token="))
- {
- Match mv = Regex.Match(line, "bdPass.api.params.login_token=\'(.+?)"\';");
- token = mv.Result("$1");
- break;
- }
- }
- sr.Close();
- req.Abort();
- resp.Close();
复制代码 另外,有人也做百度登录,他是这么说的:
get百度首页获取BAIDUID 的cookie
贴吧登录需要 BAIDUID 的cookie
得到cookie后get https://passport.baidu.com/v2/ap ... b&tangram=false
获取token
username
password
token
ppui_logintime---随便填数字
staticpage-----https%3A%2F%2Fpassport.baidu.com%2Fv2Jump.html
charset------gb2312
codestring---空
isPhone-----false
index-------0
loginType-------1
tpl-------tb//必须和上面链接中tpl值一样
callback----parent.bdPass.api.loginLite._submitCallBack
verifycode----空
mem_pass-------on
//记住cookie中的BAIDUID要携带post过去
POST以上数据到https://passport.baidu.com/v2/api/?login
就能得到BDUSScookie
综合上面的代码和另一个人的说法,能帮我看下吗。这个token应该怎么搞定。 |
|