[C#] 纯文本查看 复制代码
HttpItem itemSign = new HttpItem()
{
URL = "http://order.mi.com/site/login?ac=1",
Method = "get",
Allowautoredirect = true
};
HttpHelper http = new HttpHelper();
HttpResult httpresult = http.GetHtml(itemSign);
Cookies = httpresult.Cookie;
string CallBack = System.Uri.EscapeDataString(Regex.Match(httpresult.Html, "callback:\"([\\s\\S]*?)\"").Groups[1].Value.Trim());
string SID = System.Uri.EscapeDataString(Regex.Match(httpresult.Html, "sid:\"([\\s\\S]*?)\"").Groups[1].Value.Trim());
string QS = System.Uri.EscapeDataString(Regex.Match(httpresult.Html, "qs:\"([\\s\\S]*?)\"").Groups[1].Value.Trim());
string SIGN = System.Uri.EscapeDataString(Regex.Match(httpresult.Html, "\"_sign\":\"([\\s\\S]*?)\"").Groups[1].Value.Trim());
string HIDDEN = System.Uri.EscapeDataString(Regex.Match(httpresult.Html, "hidden:\"([\\s\\S]*?)\"").Groups[1].Value.Trim());
string serviceParam = System.Uri.EscapeDataString(Regex.Match(httpresult.Html, "serviceParam :\'([\\s\\S]*?)\'").Groups[1].Value.Trim());
// textBox3.Text = "CallBack=" + CallBack + "--SID=" + SID + "--SIGN=" + SIGN + "--QS=" + QS + "--HIDDEN=" + HIDDEN + "--serviceParam=" + serviceParam;
//登陆Post
HttpItem item = new HttpItem()
{
URL = "https://account.xiaomi.com/pass/serviceLoginAuth2",
Method = "POST",
Referer = "https://account.xiaomi.com/pass/serviceLogin",
ContentType = "application/x-www-form-urlencoded",
Postdata = string.Format("user={1}&_json=true&pwd={2}&callback={3}&sid={4}&qs={5}&hidden={6}&_sign={7}&serviceParam={8}",
"", username, password, CallBack, SID, QS, HIDDEN, SIGN, serviceParam)
};
HttpResult result = http.GetHtml(item);
// richTextBox1.Text = result.Html;
string bb =result.Cookie;
//抓包看到的第二个跳转的url
string loginurl = "https://account.xiaomi.com"+Regex.Match(result.Html, "\"location\":\"([\\s\\S]*?)\"").Groups[1].Value.Trim();
// MessageBox.Show(result.Html);
//个人中心url
String uidurl = "https://account.xiaomi.com/pass/userInfo?userId=" + Regex.Match(result.Html, "userId\":\\d{1,10}").Value.Replace("userId\":", "");
// MessageBox.Show(uidurl);
item = new HttpItem()
{
URL = loginurl,
Cookie =bb
};
result = http.GetHtml(item);
string html = result.Html;
string cookie = result.Cookie;
MessageBox.Show(cookie);
string twourl = Regex.Match(html, @"(?i)<a\shref=['""](?<href>.*?)['""].*?>here</a>
").Groups["href"].Value;
// textBox3.Text = html +"<------->"+twourl;
item = new HttpItem()
{
URL = twourl,
Cookie = cookie
};
result = http.GetHtml(item);//成功到个人账户页面
//这个cookie 为什么不对? 我抓包的结果这里应该就是最后的cookie吧
string coo1 = result.Cookie;
textBox3.Text = coo1;
//这个cookie访问个人中心不行
item = new HttpItem()
{
URL = loginurl,
};
result = http.GetHtml(item);
string html1 = result.Html;
richTextBox1.Text = html1;
代码如上,自己按照手动登陆抓包一步一步写的,但是为什么最后得出来的cookie是不可以用的。。 每一步得出cookie都是不可以访问购物车一类的。迷惑了, 自己 刚接触C#不久 求大大们解答
|