Proxy plans now up to 15% cheaper
View pricing

C# (.NET HttpClient)

Use a proxy in C# with HttpClient and WebProxy. Add credentials and route requests through HTTP or SOCKS5 with code examples.

Integrations5 min read

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.

Note

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

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.

C#
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": "...", ...}
Warning

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:

C#
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);
Tip

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.

C#
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);
Warning

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):

C#
// 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:

C#
// 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")
};
Warning

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.

Tip

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:

C#
// 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);
Note

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

Next steps

Need a tailored proxy plan for a large project?

Need a different speed or traffic allowance? Contact us through the channels on our website so we can assess whether a custom plan is possible.

Contact Our Sales TeamTelegram & ticket support · English and Arabic