Пример #1
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            string username = this.txtUsername.Text;
            string password = this.txtPassword.Text;
            string postData = string.Format("username={0}&password={1}&code=&return_url=https%3A%2F%2Fshop.48.cn%2Fhome%2Findex", username, password);

            string loginResult = util.POST("http://user.snh48.com/Login/dologin.html", cc, postData);

            if (loginResult.Contains("{\"status\":\"1001\""))
            {
                ShowError("用户名或密码错误");
            }
            else
            {
                // 登录成功 ,解析返回的 url
                loginResult = loginResult.Replace("\\", "");
                this.Text   = username;

                /*
                 * <script type="text/javascript" src="http://user.snh48.com/api/uc.php?time=1541052675&code=a498X77nX" reload="1"><\/script>
                 */
                Regex           regex           = new Regex(" src=\".{10,700} reload");
                MatchCollection matchCollection = regex.Matches(loginResult);

                // 分别向每个独立的url地址发请求
                Task.Factory.StartNew(() =>
                {
                    foreach (var item in matchCollection)
                    {
                        string text2 = item.ToString();
                        int num      = text2.IndexOf("?");
                        string url   = text2.Substring(6, text2.Length - 14);
                        util.GET(url, this.cc);
                    }
                }).ContinueWith(t => {
                    login = true;
                    this.btnBuyOne.Enabled   = true;
                    this.btnBuyGoods.Enabled = true;
                    this.gbLogin.Enabled     = false;
                });
            }
        }