Connect to a .NET web service through a SOCKS5 proxy

I am trying to connect through a SOCKS5 proxy to a web service. Currently my app.config is as follows:

<system.net>
 <defaultProxy enabled="true"  >
  <proxy proxyaddress="http://xxx.xxx.xxx.xxx:yyyy" bypassonlocal="True" />
 </defaultProxy>
</system.net>

This works great for HTTP proxies, however it just doesn't connect to SOCKS5. I searched many times for the answer and could not find anyone to solve this problem, although I found this question a couple of times. Does anyone know how I can do this?

+3
source share
3 answers

Apparently, Microsoft has not created SOCKS proxy support in its web classes (see http://windows-tech.info/13/f17246e7dd4a8a2b.php )

, - .NET - SOCKS5 . , - .NET- Reflector, Mono , ProxySocket, .

, , , , .

+2

webservice GetWebRequest GetWebResponse. # socks http://www.codeproject.com/Articles/5954/C-class-for-connecting-via-a-SOCKS-Proxy-Server - .

, , - - socks WideCap. - socks.

0

If you can use HttpClient , you can use SocksSharp .

I just followed suit and it worked for me.

var settings = new ProxySettings()
{
    Host = "xxx.xxx.xxx.xxx",
    Port = yyyy
};

using (var proxyClientHandler = new ProxyClientHandler<Socks5>(settings))
{
    using (var httpClient = new HttpClient(proxyClientHandler))
    {
        var response = await httpClient.GetAsync("http://example.com/");
    }
}
0
source

Source: https://habr.com/ru/post/1707359/


All Articles