The Proxy Client library allows the user to send and receive requests over Http, Socks4/4a/5 proxies.
Install as Nuget Package
Install-Package Proxy.Client
.NET CLI:
dotnet add package Proxy.Client
using(var socks4ProxyClient = new Socks4ProxyClient("212.86.75.9", 4153))
{
var response = await socks4ProxyClient.GetAsync("https://www.example.com/");
}
using(var socks4ProxyClient = new Socks4ProxyClient("212.86.75.9", 4153))
{
var proxyHeaders = new List<ProxyHeader>
{
ProxyHeader.Create("User-Agent", "My-UserAgent"),
ProxyHeader.Create("Cache-Control", "no-cache")
};
var response = await socks4ProxyClient.GetAsync("https://www.example.com/", headers: proxyHeaders);
}
using(var socks4ProxyClient = new Socks4ProxyClient("212.86.75.9", 4153))
{
var proxyCookies = new List<Cookie>
{
new Cookie("Id", "a3fWa"),
new Cookie("Expires", "Thu, 31 Oct 2021 07:28:00 GMT")
};
var response = await socks4ProxyClient.GetAsync("https://www.example.com/", cookies: proxyCookies);
}
Below is an example of a request with a 10 second total timeout and 1 second read/write timeout:
using(var socks4ProxyClient = new Socks4ProxyClient("212.86.75.9", 4153))
{
var response = await socks4ProxyClient.GetAsync("https://www.example.com/", totalTimeout: 10000, readTimeout: 1000, writeTimeout: 1000);
}
By default, all connections are persistent. To force the connection/socket closure, set the isKeepAlive flag to False:
using(var socks4ProxyClient = new Socks4ProxyClient("212.86.75.9", 4153))
{
var response = await socks4ProxyClient.GetAsync("https://www.example.com/", isKeepAlive: False);
}
Feel free to open an issue or submit a pull request.