Answer the question
In order to leave comments, you need to log in
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();
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question