SocketToMe
SocketToMe copied to clipboard
Exception is thrown at multiple HTTP requests in a row
Consider this simple code example:
var socksEndpoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 9050);
var socks5Client = new Socks5Client();
var socket = socks5Client.ConnectToServer(socksEndpoint);
socket = socks5Client.ConnectToDestination(socket, "icanhazip.com", 80);
var handler = new NetworkHandler(socket);
using (var httpClient = new HttpClient(handler))
{
var content = httpClient.GetAsync("http://icanhazip.com/").Result.Content.ReadAsStringAsync().Result;
Console.WriteLine($"Your TOR IP: \t\t{ content}");
content = httpClient.GetAsync("http://icanhazip.com/").Result.Content.ReadAsStringAsync().Result;
Console.WriteLine($"Your TOR IP: \t\t{ content}");
}
The problem is at the second httpClient.GetAsync request it throws the following exception:
{"Unable to read data from the transport connection: An established connection was aborted by the software in your host machine."}
The problem is in the NetworkHandler class, I am not sure what's going on there.
It looks like it has something to do with http://icanhazip.com/
Other requests don't seem to be suffering from the same problem. Like this:
var socksEndpoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 9050);
var socks5Client = new Socks5Client();
var socket = socks5Client.ConnectToServer(socksEndpoint);
socket = socks5Client.ConnectToDestination(socket, "api.qbit.ninja", 80);
var handler = new NetworkHandler(socket);
using (var httpClient = new HttpClient(handler))
{
var content = httpClient.GetAsync("http://api.qbit.ninja/balances/akEBcY5k1dn2yeEdFnTMwdhVbHxtgHb6GGi?from=tip&until=336000").Result.Content.ReadAsStringAsync().Result;
Console.WriteLine(content);
content = httpClient.GetAsync("http://api.qbit.ninja/balances/akEBcY5k1dn2yeEdFnTMwdhVbHxtgHb6GGi?from=tip&until=336000").Result.Content.ReadAsStringAsync().Result;
Console.WriteLine(content);
content = httpClient.GetAsync("http://api.qbit.ninja/balances/akEBcY5k1dn2yeEdFnTMwdhVbHxtgHb6GGi?from=tip&until=336000").Result.Content.ReadAsStringAsync().Result;
Console.WriteLine(content);
}
I will close the issue, if you are not interested further investigating it. (I am not that much.)
Just note: without NetworkHandler, normal http requests can go in a row to http://icanhazip.com/