This guide shows how to set up a C# proxy with HttpClient, WebProxy, and NetworkCredential. You route .NET HTTP traffic through ColdProxy's gateway gw-{service-id}.coldproxy.com on any port in 30000-34999, working the same way on HttpClientHandler and the modern SocketsHttpHandler. It supports HTTP and HTTPS over TCP and (on .NET 6+) SOCKS5, and switches between rotating and sticky exits through ColdProxy's username tags. The examples use gw-2312.coldproxy.com (replace 2312 with your service/package ID) and the credentials from your client area. For background on the auth models, see IP whitelisting vs username/password.
Residential IPv4 (GB Based) and Residential IPv6 activate instantly after payment clears. Residential IPv4 (Unmetered) and Datacenter IPv6 set up automatically; allow up to 10 minutes after payment clears and connect as soon as setup completes. See Activation and setup times.
Connection details
| Setting | Value |
|---|---|
| Host | gw-{service-id}.coldproxy.com — examples use gw-2312 |
| Port | Any in 30000-34999 (use 30000 in examples) |
| Protocols | HTTP, HTTPS (TCP) and SOCKS5 (TCP/UDP), auto-detected |
| Auth | USERNAME:PASSWORD, or IP whitelisting (up to 50 IPs) |
| String format | gw-2312.coldproxy.com:PORT:USERNAME:PASSWORD |
HttpClient proxy with WebProxy (HTTP/HTTPS)
Create a WebProxy for the gateway, attach a NetworkCredential, and pass it to a handler. ColdProxy auto-detects the protocol, so an http:// proxy scheme handles both HTTP and HTTPS targets.
using System;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
var proxy = new WebProxy("http://gw-2312.coldproxy.com:30000")
{
Credentials = new NetworkCredential("USERNAME", "PASSWORD")
};
var handler = new HttpClientHandler
{
Proxy = proxy,
UseProxy = true
};
using var client = new HttpClient(handler);
var body = await client.GetStringAsync("https://api.vipv6proxy.com/api/checker/my-ip");
Console.WriteLine(body); // JSON: {"ip": "...", "version": ..., "country": "...", ...}Set the credentials on the WebProxy.Credentials property, not on HttpClientHandler.Credentials. Credentials embedded in the proxy URL (for example http://USERNAME:PASSWORD@host:port) are silently dropped by WebProxy and the request fails with 407. Always pass them via NetworkCredential.
For production, prefer SocketsHttpHandler (or IHttpClientFactory), which exposes pooling and connect-timeout controls. The proxy setup is identical:
using System.Net;
using System.Net.Http;
var handler = new SocketsHttpHandler
{
Proxy = new WebProxy("http://gw-2312.coldproxy.com:30000")
{
Credentials = new NetworkCredential("USERNAME", "PASSWORD")
},
UseProxy = true,
PooledConnectionLifetime = TimeSpan.FromMinutes(2)
};
using var client = new HttpClient(handler);Verify the exit IP and location with the Proxy Checker and What Is My IP tools before scaling up.
SOCKS5 on .NET 6+
SocketsHttpHandler added native SOCKS4, SOCKS4a, and SOCKS5 support in .NET 6. Use a socks5:// scheme in the WebProxy URI. ColdProxy SOCKS5 runs over TCP and UDP.
using System.Net;
using System.Net.Http;
var proxy = new WebProxy("socks5://gw-2312.coldproxy.com:30000")
{
Credentials = new NetworkCredential("USERNAME", "PASSWORD")
};
var handler = new SocketsHttpHandler { Proxy = proxy, UseProxy = true };
using var client = new HttpClient(handler);
var body = await client.GetStringAsync("https://api.vipv6proxy.com/api/checker/my-ip");
Console.WriteLine(body);As with HTTP, do not embed USERNAME:PASSWORD in the socks5:// URI; .NET does not extract userinfo from a SOCKS proxy URL into the authentication flow. Set credentials only through the Credentials property. See SOCKS5 vs HTTPS proxies and TCP vs UDP proxies.
Rotating vs sticky sessions
ColdProxy encodes geo-targeting and session behavior in the username, using a user-key-value-key-value... grammar (full reference: Username tag scheme). You switch between a fresh IP per request and a held IP by changing the username passed to NetworkCredential: no separate API call.
Rotating (new IP per request)
With no session tag, each request gets a new IP. Add geo tags to target a country/state/city (here a rotating US exit):
// Rotating US exit IP — confirm the exact country prefix in your client area
var proxy = new WebProxy("http://gw-2312.coldproxy.com:30000")
{
Credentials = new NetworkCredential("user-country-us", "PASSWORD")
};Sticky (hold the same IP)
A sticky session needs both a session tag and a time (duration) tag together; supplying only one rotates per request. This holds one US IP for 10 minutes:
// Sticky US IP for 10 minutes — same session ID + duration reuses the exit IP
var proxy = new WebProxy("http://gw-2312.coldproxy.com:30000")
{
Credentials = new NetworkCredential("user-country-us-session-481516-time-10m", "PASSWORD")
};The exact segment prefixes (for example the keys for country, session, and time) are configured per product by ColdProxy; confirm the exact prefixes for your plan in your client area before deploying. Sticky duration limits: Residential IPv4 supports 5s to 24h; Residential IPv6 and Datacenter IPv6 support 5s up to FOREVER.
For the concepts, see rotating and sticky proxies explained and geo-targeting with proxies.
HttpClientHandler locks its configuration once the first request is sent. To rotate the username per request (for example a new sticky session ID each batch), build a new handler/client per rotation or reuse one client per session. Wrap HttpClient in a long-lived instance per session rather than creating one per request to avoid socket exhaustion.
IP whitelist alternative
Authorize your server's public IP (up to 50 addresses) in the client area and you can skip credentials entirely; omit the NetworkCredential:
// IP-authenticated — no NetworkCredential
var handler = new HttpClientHandler
{
Proxy = new WebProxy("http://gw-2312.coldproxy.com:30000"),
UseProxy = true
};
using var client = new HttpClient(handler);IP authentication and username/password can both be active at once. With IP-auth and no username tags, the geo defaults to Worldwide. To bind geo-targeting and sticky behavior to specific ports without per-request username tags, configure SuperPorts (port-range rules) in your client area (for example, ports 30000-31000 fixed to US with a 10-minute sticky window).
Verify and troubleshoot
- Confirm reachability, exit IP, and location with the Proxy Checker and What Is My IP tools.
- A
407almost always means credentials were set on the wrong object or embedded in the URL; keep them onWebProxy.Credentials. See Common errors & fixes and proxy error codes 407, 403, 429, 502, 504. - On an IPv6 plan, check the target with the IPv6 Checker first; IPv4-only sites (no AAAA record) will fail over IPv6. See IPv6 reachability for the confirmed-platform list and CDN-aware routing.
Next steps
- Compare plans and short paid validation options on pricing and the proxy product pages.
- See proxy automation and API integration for building rotation and provisioning into a .NET service.