Proxy in C# HttpClient with a password
In .NET a password proxy is set through WebProxy and an HttpClientHandler. Below is a console app that prints the IP.

Why use a proxy in C# HttpClient
HttpClient is the standard .NET HTTP client. The proxy is assigned to the Proxy property of HttpClientHandler or SocketsHttpHandler with UseProxy = true. Login and password are set through NetworkCredential in WebProxy.Credentials.
Start with HTTP: it works in every .NET version. For background services with a stream of requests enable rotation; for working with one account, a sticky session.
Residential
from $0.6 / GBHome ISP addresses. The main choice for accounts and protected sites.
VIP
$2 / GBHand-picked clean IPs, faster and more stable than regular residential.
Mobile
$4 / GBCarrier IPs, for platforms that check addresses strictly.
Step-by-step setup
Button names are given exactly as they appear in C# HttpClient.
Create a project
Run dotnet new console -n ProxyIp and replace Program.cs with the example code.
Export the proxy
Take an HTTP proxy in @SousProxyBot or the dashboard: host, port, login and password.
Configure WebProxy
Pass the address to the WebProxy constructor, login and password to Credentials via NetworkCredential.
Attach the handler
Create an HttpClientHandler with Proxy = proxy and UseProxy = true, then pass it to new HttpClient(handler).
Run and check the IP
Run dotnet run. The console shows JSON with the proxy address.
Code example
Put in your own HOST, PORT, LOGIN and PASSWORD from the bot or the dashboard.
using System.Net;
var proxy = new WebProxy("http://HOST:PORT")
{
Credentials = new NetworkCredential("LOGIN", "PASSWORD"),
};
var handler = new HttpClientHandler { Proxy = proxy, UseProxy = true };
using var client = new HttpClient(handler) { Timeout = TimeSpan.FromSeconds(15) };
string body = await client.GetStringAsync("https://api.ipify.org?format=json");
Console.WriteLine(body);
Tested by running it
We ran this example ourselves: .NET 8.0.34 (SDK 8.0.134) · HttpClient. Real output below, IP hidden.
$ dotnet run {"ip":"proxy IP"}
And this is the response when the password is wrong:
$ dotnet run
…
at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
at System.Net.Http.HttpClient.GetStringAsyncCore(HttpRequestMessage request, CancellationToken cancellationToken)
at Program.<Main>$(String[] args) in /home/user/proxy-test/Program.cs:line 11
at Program.<Main>(String[] args)Check that it works
Open these pages through C# HttpClient with the proxy on.
Common errors
The issues people most often bring to support.
HttpRequestException: 407 (Proxy Authentication Required)Login and password aren't passed or are wrong. Make sure Credentials is set on the WebProxy, not on the HttpClientHandler.
InvalidOperationException when changing ProxyProxy can't be changed after the first request. For another proxy create a new handler and client.
Requests bypass the proxyCheck UseProxy = true and that the handler is passed to the HttpClient constructor.
Running out of sockets with many clientsDon't create an HttpClient per request. Keep one client per proxy and reuse it.
FAQ
Is SOCKS5 supported?
In .NET 6 and newer WebProxy accepts a socks5://HOST:PORT address. Login and password go through the same NetworkCredential, but we haven't tested this live, so start with HTTP.
How do I give different requests different IPs?
One client, one proxy. For different sticky sessions create separate HttpClientHandlers with different credentials from the dashboard.
How do I test the proxy itself?
Run the line through /en/tools/proxy-checker/ to separate a proxy problem from a code problem.
