Пример #1
0
        public void ExecuteWork(object sender, DoWorkEventArgs e)
        {
            ProgressLabel.Text = "Logging in!";
            Worker.ReportProgress(20);

            var result = Client.Get("/login.php");

            Thread.Sleep(300);

            var html = result.Content.ReadAsStringAsync().Result;

            Worker.ReportProgress(40);

            Thread.Sleep(300);

            Worker.ReportProgress(60);

            var ftHiddenField = HtmlReader.Find(html, "//input[@name='ft']");
            var ft            = ftHiddenField.Attributes.FirstOrDefault(x => x.Name == "value").Value;

            var loginHiddenField = HtmlReader.Find(html, "//input[@name='login']");
            var login            = loginHiddenField.Attributes.FirstOrDefault(x => x.Name == "value").Value;

            var content = new FormUrlEncodedContent(new[]
            {
                new KeyValuePair <string, string>("ft", ft), // get from html
                new KeyValuePair <string, string>("user", PlayerAccount.AccountName),
                new KeyValuePair <string, string>("pw", PlayerAccount.Password),
                new KeyValuePair <string, string>("s1", "login"),
                new KeyValuePair <string, string>("w", "1920:1080"),
                new KeyValuePair <string, string>("login", login), // get from html
            });

            Thread.Sleep(300);

            Worker.ReportProgress(80);

            Thread.Sleep(300);

            result = Client.Post("/login.php", content);

            html = result.Content.ReadAsStringAsync().Result;

            Worker.ReportProgress(100);

            e.Result = html;
        }