E
E
e_danilchenko2016-03-31 15:48:53
C++ / C#
e_danilchenko, 2016-03-31 15:48:53

How to work with tor in C#?

Good afternoon! The problem is this: you need to send a request to the site w-th tor. This is achieved through such a simple design

HttpWebRequest reqPOST = HttpWebRequest.CreateHttp(@"...");
            reqPOST.Method = "POST"; // Устанавливаем метод передачи данных в POST
            reqPOST.Timeout = 120000; // Устанавливаем таймаут соединения
            reqPOST.Headers.Set(HttpRequestHeader.Cookie, this.cookies);
            reqPOST.UserAgent = this.agents[0];
            reqPOST.Proxy = new WebProxy("127.0.0.1:9050");//порт с тором
            reqPOST.ContentType = "multipart/form-data";
            byte[] sentData = Encoding.GetEncoding(65001).GetBytes(..............

But the scoundrel Tor does not want to work like this and writes such things to the console: "Socks version 80 not recognized. (Tor is not an http proxy)". I don’t seem to be a fool, I washed away what was written, I even found something about this on the net, but I just can’t understand what exactly needs to be changed. Help me please.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladimir Martyanov, 2016-03-31
@vilgeforce

Tor is not an http proxy, and you are breaking into it like an HTTP proxy. Break like a SOCKS proxy and you will be happy. Just need to clarify what version of SOCKS it has: fourth or fifth ...

H
Haze Max, 2016-08-29
@hazemax

2 solutions
1) The first one is simple. Use the xNet library. As far as I know, work with socks is implemented there
2) If you need to make socks proxy work through WebRequest, then the solution is as follows:
Download the library link
Then create descendants of SocksHttpWebResponse and SocksHttpWebRequest inheriting from WebResponse and WebRequest as shown link
You can use it like this

WebRequest _request;
WebResponse _response;
WebProxy proxy = new WebProxy(new Uri("socks5://192.168.0.111:1080"));
if (_proxy.Address.Scheme.Contains("socks"))
_request = SocksHttpWebRequest.Create(url);
else
_request = WebRequest.Create(url);

_request.Proxy = _proxy;

            // ну а дальше все как обычно

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question