Quite a long time ago I decided to write software for creating botnets in social networks. It all started with an instagram, but there I was soon banned by ip, and I somehow podgas. After some time I decided to rewrite the project under vk. And so, I have an authorization method. I’m from Ukraine, I simply cannot test authorization without a proxy (and access to many clients at the same time from a single ip is not the best idea), it probably has shortcomings, but this is not the case now. I do not understand why, but with proxy I just don’t get html. Proxy use fresh, http http. Here is the code:

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Net.Http; using Newtonsoft.Json; using HtmlAgilityPack; using System.Net; using System.IO; using System.Text.RegularExpressions; namespace vkbot { class VK : IDisposable { const string USER_AGENT = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_3) " + "AppleWebKit/537.36 (KHTML, like Gecko) " + "Chrome/45.0.2414.0 Safari/537.36"; HttpClientHandler m_handler; HttpClient m_client; public VK() { m_handler = new HttpClientHandler(); m_client = new HttpClient(m_handler); m_client.BaseAddress = new Uri("https://vk.com/"); m_client.DefaultRequestHeaders.UserAgent.ParseAdd(USER_AGENT); m_handler.UseProxy = true; m_handler.Proxy = new WebProxy("89.175.129.145:55653"); } public void Dispose() { m_client.Dispose(); m_handler.Dispose(); } async void GetCookie() { await m_client.GetAsync("/login/"); //var cookies = m_handler.CookieContainer.GetCookies(m_client.BaseAddress); } public async Task<string> LoginAsync(string username, string password) { HtmlDocument document = new HtmlDocument(); document.LoadHtml(await m_client.GetAsync("/login").Result.Content.ReadAsStringAsync()); string ip_h = Convert.ToString(document.DocumentNode.SelectSingleNode("/html/body/div[13]").InnerHtml); var cookies = m_handler.CookieContainer.GetCookies(m_client.BaseAddress); HttpRequestMessage message = new HttpRequestMessage(HttpMethod.Post, "/login/"); message.Headers.Host = "login.vk.com"; message.Headers.Referrer = m_client.BaseAddress; Dictionary<string, string> fields = new Dictionary<string, string>() { {"_origin", Convert.ToString(m_client.BaseAddress)}, {"act","login" }, {"email",username}, {"pass",password }, {"role","al_frame" } }; var responce = await m_client.SendAsync(message); return responce.ToString(); } } } 

Proxy initialized in the constructor, this is a temporary measure if that.

PS Now I ask for help with the proxy, but if you have something to say about the rest of the code, write. I will be grateful.

  • one
    Using .Result kills asynchrony. / It would be nice to call where you need Dispose() or wrap everything in using . - Alexander Petrov

1 answer 1

Why do not you use the library to work with VK ? For example, vkNet. And do not worry, why your request does not work.

In a more general case, take an HTTP sniffer and see how the original request from the browser differs from yours.

It is also worth saying that http-proxy is so-so. Take Socks5. And be sure to check the proxy through ProxyChecker.