Problems with proxy c#
Very long ago I decided to write software for creating botnets in social networks. It all started with Instagram, but there I was soon banned on the IP, and I somehow podugas. After a while, I decided to rewrite the project under vk. And so, I have an authorization method. Tk I'm from Ukraine, I simply can't test authorization without a proxy(and access to many clients at the same time from one IP is not the best idea), probably there are shortcomings in it, but this is not about that now. I don't know why, but with proxies, I just don't get html. I use fresh, stogo http proxies. 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();
}
}
}
The proxy initialized in the constructor, this is a temporary measure if anything.
PS now I ask you to help with the proxy, but if you have something to say about the rest of the code - write. I would be grateful.
1 answers
Why don't you use libraries to work with VK? For example, vkNet. And don't worry about why your request doesn't work.
In a more general case, take the HTTP sniffer and see how the original request from the browser differs from yours.
It is also worth saying that the http proxy is-so-so. Take Socks5. And be sure to check the proxy via ProxyChecker.