Skip to content

Instantly share code, notes, and snippets.

@quantumproxies
Created July 28, 2026 09:47
Show Gist options
  • Select an option

  • Save quantumproxies/ed29285309aac9df5d3d0d4026c7dd54 to your computer and use it in GitHub Desktop.

Select an option

Save quantumproxies/ed29285309aac9df5d3d0d4026c7dd54 to your computer and use it in GitHub Desktop.
C# HttpClient with an authenticated residential proxy (.NET 6+, WebProxy + NetworkCredential) — https://quantumproxies.io/residential-proxies
// C# HttpClient behind an authenticated residential proxy (.NET 6+).
//
// Notes that save you an afternoon:
// - WebProxy + NetworkCredential handles the 407 dance automatically.
// - Reuse ONE HttpClient; a new handler per request leaks sockets.
// - Geo flags live in the proxy username (-country-de, -session-x1-lifetime-10).
//
// Proxy: QuantumProxies residential — https://quantumproxies.io/residential-proxies
// Credentials: https://app.quantumproxies.io/register
using System.Net;
var user = (Environment.GetEnvironmentVariable("QP_USER") ?? "YOUR_USERNAME") + "-country-us";
var pass = Environment.GetEnvironmentVariable("QP_PASS") ?? "YOUR_PASSWORD";
var handler = new HttpClientHandler
{
Proxy = new WebProxy("http://residentialboson.quantumproxies.io:9000")
{
Credentials = new NetworkCredential(user, pass)
},
UseProxy = true,
};
using var client = new HttpClient(handler);
var json = await client.GetStringAsync("https://ipinfo.io/json");
Console.WriteLine(json);
// Sticky session variant (same exit IP for 10 minutes — port 10000):
// new WebProxy("http://residentialboson.quantumproxies.io:10000")
// user = $"{baseUser}-country-us-session-cs1-lifetime-10"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment