Created
July 28, 2026 09:47
-
-
Save quantumproxies/b154710671ef26a1af8f4c87cc553bf0 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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