HttpToSocks5Proxy

repository·main·Indexed 42 days ago

https://github.com/mihazupan/httptosocks5proxy

A library that enables SOCKS proxy support for HttpClient in older versions of .NET. It allows routing HttpClient requests through a SOCKS5 proxy, providing a solution for projects that cannot use the native SOCKS proxy support introduced in .NET 6 and later via SocketsHttpHandler.

Tokens
284
Snippets
1
Records
2
Agent score
3%

What's inside HttpToSocks5Proxy

  1. Important notice regarding .NET version compatibility

    main
    If you are using .NET 6 or newer, you do not need this library. SocketsHttpHandler now provides native support for connecting to Socks4, Socks4a, and Socks5 proxies. Use this library only if you are targeting older versions of .NET.
  2. Use HttpToSocks5Proxy with HttpClient

    main

    This library allows you to route HttpClient requests through a SOCKS5 proxy. While modern .NET (version 6 and later) supports SOCKS proxies natively via SocketsHttpHandler, this library remains useful for projects running on older versions of .NET.

    To use it, instantiate a SocketsHttpHandler, set its Proxy property to a new WebProxy using a socks5:// URI scheme, and pass that handler to your HttpClient constructor.

    var client = new HttpClient(new SocketsHttpHandler()
    {
        Proxy = new WebProxy("socks5://127.0.0.1:9050")
    });
    
    var content = await client.GetStringAsync("https://check.torproject.org/");
    Console.WriteLine(content);