I
I
Igor Karachentsev2019-02-27 11:12:49
.NET
Igor Karachentsev, 2019-02-27 11:12:49

How to log in to vk through a POST request?

I'm trying to log in to vk through the form. I parsed the form, got the necessary fields. Next, I make a request through HttpClient:

Dictionary<string, string> parameters = new Dictionary<string, string>
            {
                {"email", userEmail},
                {"pass", userPassword},
                {"role", "al_frame"},
                {"_origin", "https://vk.com"},
                {"ip_h", ipH},
                {"lg_h", lgH},
                {"utf8", "1"},
                {"expire", ""},
                {"recaptcha", ""},
                {"captcha_sid", ""},
                {"captcha_key", ""}
            };
 
            FormUrlEncodedContent encodedContent = new FormUrlEncodedContent(parameters);
 
            CookieContainer cookies = new CookieContainer();
            //HttpClientHandler handler = new HttpClientHandler() { AllowAutoRedirect = false };
            //handler.CookieContainer = cookies;
 
            using (var handler = new HttpClientHandler() {
                CookieContainer = cookies,
                AllowAutoRedirect = true
            })
            using (HttpClient client = new HttpClient(handler))
            {
                Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
                Encoding.GetEncoding("windows-1251");
 
                //client.BaseAddress = new Uri(baseUrl);
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/x-www-form-urlencoded"));
                client.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.109 Safari/537.36");
                client.DefaultRequestHeaders.Add("Referer", "https://vk.com");
                client.DefaultRequestHeaders.Add("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");
                HttpResponseMessage result = await client.PostAsync("https://login.vk.com/?act=login", encodedContent);
 
                CookieCollection cookiesResp = cookies.GetCookies(new Uri(baseUrl));
               
                foreach (Cookie cookie in cookiesResp)
                {
                    //Console.WriteLine(cookie.ToString());
                    cookies.Add(new Uri(baseUrl), cookie);
                }
 
                string resultContent = await result.Content.ReadAsStringAsync();
 
                Console.WriteLine(resultContent);
            }
 
            Console.ReadKey();

Nothing comes out of the output. The headers seem to be correct, and the following piece of js is given in the resultContent:
5c7645f71e9e7454853095.jpeg
What can it be? How to win?
Sharps just started to study. Before that, I did exactly the same procedure in php, everything worked correctly there. Authorization is needed through the form, not through the API.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question