前不久正好也想写个小米抢购的辅助工具,首先要解决的当然就是登陆。 
本人c#初学者,所以起初从网上搜索了些许资料(当然大多是别人已经提供思路的),结合实践和 
自身理解,最后把代码diy成了下面模样,也是能得到cookie的。  
第一次逛这个论坛,潜水看了些许帖子,果断注册,正好看到此贴,把我的代码页贴出来, 
算是跟大家分享,也希望经验者指导。  {:soso_e106:} 
 
         [C#] 纯文本查看 复制代码    string id = this.txtUserName.Text;
            string password = this.txtPwd.Text;
            // login start
            string requestUriString = "https://account.xiaomi.com/pass/serviceLoginAuth2";
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(requestUriString);
            request.CookieContainer = new CookieContainer();
            request.CookieContainer = m_Cookie;
            request.Method = "POST";
            request.AllowAutoRedirect = true;
            request.ContentType = "application/x-www-form-urlencoded";
            byte[] bytes = Encoding.UTF8.GetBytes("passToken=&user=" + id + "&pwd=" + password + "&callback=https%3A%2F%2Faccount.xiaomi.com&sid=passport&qs=%253Fsid%253Dpassport&hidden=&_sign=KKkRvCpZoDC%2BgLdeyOsdMhwV0Xg%3D");
            request.ContentLength = bytes.Length;
            Stream requestStream = request.GetRequestStream();
            requestStream.Write(bytes, 0, bytes.Length);
            this.loginResponse = (HttpWebResponse)request.GetResponse();
            m_Cookie = request.CookieContainer;
            this.loginRespReader = new StreamReader(this.loginResponse.GetResponseStream());
            //  login end
            if (loginRespReader.ReadToEnd().Contains("小米帐户 - 登录"))
            {
                this.AppendText(text + "登陆失败\n");
            }
            else
            {
                this.AppendText(text + "登陆成功");    
            }
 |