Skip to content

Updated

C# HttpClient Proxy With Login:
.NET 8 and 9 Setup

  1. Create a WebProxy with the proxy address, give it Credentials (a NetworkCredential with your login and password), put it in the Proxy property of a SocketsHttpHandler or HttpClientHandler, and build one HttpClient from that handler.
  2. Reuse that client for the life of the app.
  3. For a Proxy302 IP the address is http://HOST:2222 for an HTTP proxy; SOCKS5 on port 3333 works through a socks5:// address in .NET 6 and later. Fetch https://ipinfo.io/json first to see the exit address.

Check it right after buyingExample output

curl -x http://USER:PASS@HOST:PORT https://ipinfo.io/json

ip
203.0.113.24
country
US
Matches the country you picked
Day 15
203.0.113.24
Same address for the whole term
Example addresses (203.0.113.0/24), not real exits
01 / 09Three places to set a proxy

A short program that sends a request through a proxy with a username and password, and what changes for SOCKS5 or a default proxy.

Three places to set a proxy

Three places to set a proxy
ItemReachLogin
Handler.Proxy (WebProxy)The one HttpClient built from that handler; overrides the defaultSet on the WebProxy.Credentials property
HttpClient.DefaultProxyEvery HttpClient that has no proxy of its ownNot set in code here; it is read from the environment or system settings
HTTP_PROXY / HTTPS_PROXYFeed the default proxy on Windows and LinuxMay be written in the URL as http://LOGIN:PASSWORD@HOST:2222; the URL must start with http, not https

Microsoft Learn pages read on 20 November 2026.

A minimal program with an HTTP proxy and login

using System.Net;

var proxy = new WebProxy(new Uri("http://HOST:2222"))
{
    Credentials = new NetworkCredential("LOGIN", "PASSWORD")
};

var handler = new SocketsHttpHandler
{
    Proxy = proxy,
    UseProxy = true
};

// Create one HttpClient and reuse it for the whole life of the app
using var client = new HttpClient(handler)
{
    Timeout = TimeSpan.FromSeconds(30)
};

var json = await client.GetStringAsync("https://ipinfo.io/json");
Console.WriteLine(json);

Example for .NET 8 or 9 (top-level statements). Replace HOST, LOGIN and PASSWORD with the values in My assets. Not compiled here.

SOCKS5 instead of HTTP

using System.Net;

// Same code as above, only the proxy line changes (SOCKS5 port 3333).
// Use the Uri overload of WebProxy.
var proxy = new WebProxy(new Uri("socks5://HOST:3333"))
{
    Credentials = new NetworkCredential("LOGIN", "PASSWORD")
};

Example. .NET 6 and later accept the socks5 scheme. The .NET blog does not state that a SOCKS username and password are supported, so test it; if it fails with the right login, use the HTTP proxy on port 2222.

Step by step

  1. Step 1

    Get an IP and copy HOST, port, LOGIN and PASSWORD from My assets. HTTP goes with port 2222, SOCKS5 with 3333.

  2. Step 2

    Paste the program above into a console project, replace the placeholders and run it.

    Expected result JSON from ipinfo.io whose ip field is the proxy's address, not yours.

  3. Step 3

    Move the handler and client creation to one place (a static field or a dependency-injection singleton) so the whole app reuses one HttpClient.

  4. Step 4

    Catch HttpRequestException and read StatusCode; catch TaskCanceledException for a timeout and look at its inner exception.

One shared client and rotating IPs

Microsoft recommends reusing HttpClient for the life of the app. That matters for a rotating proxy: Proxy302 rotating lines give a new IP to each new connection, and a reused client keeps connections alive, so several requests can leave from the same IP. If you need a new IP per request, create a new connection each time, for example with a separate handler for that job; if you need to keep one IP, use a static IP or a session on the line.

A static or datacenter IP bought per IP does not rotate during its lease, which suits one long-running client.

If the request fails

HttpRequestException with StatusCode 407

Check Whether Credentials is set on the WebProxy and LOGIN and PASSWORD match My assets.

Fix Add or correct the credential and run again.

TaskCanceledException after the timeout

Check Whether the inner exception is a TimeoutException, and whether HOST and port are right and not blocked by your network.

Fix Test the same proxy with curl from the same machine; raise Timeout only if curl is slow too.

The exit address is still your own

Check That UseProxy is true, the handler is the one passed to HttpClient, and the WebProxy was built with an address (the empty constructor uses no proxy).

Fix Fix the wiring and print the ip field again.

An error with an https:// proxy address

Check For an HTTP proxy the address starts with http://; Microsoft notes that proxy URLs in the environment variables must start with http.

Fix Change the scheme to http (or socks5 for SOCKS5).

Prices and limits

A datacenter IP costs US$0.25 for 1 day and US$3.99 for 30 days, and a static ISP IP US$0.50 for 1 day and US$7.99 for 30 days, the same in every country; an order takes 1 to 100 IPs. HTTP uses port 2222 and SOCKS5 port 3333. Rotating residential starts at US$1.50 per GB on the Budget line. There is no free trial.

C# HttpClient proxy: FAQ

How do I set a proxy on HttpClient in C#?

Build a WebProxy with the address, set its Credentials, put it in the handler's Proxy property and create the HttpClient from that handler.

Does HttpClient support SOCKS5?

Yes, from .NET 6, with a socks5:// address. The .NET blog does not say that a SOCKS username and password are supported, so test them or use HTTP on port 2222.

Should I create a new HttpClient for every request?

No. Microsoft recommends reusing instances during the application lifecycle.

Can I put the login in the proxy URL?

For the HTTP_PROXY and HTTPS_PROXY variables yes, as http://LOGIN:PASSWORD@HOST:2222. In code, set WebProxy.Credentials.

How much does a datacenter IP cost?

US$0.25 for 1 day and US$3.99 for 30 days, the same in every country.

Further reading

Setup guides Proxy302 publishes on GitHub on the same topic:

Reference links

5
  1. Microsoft Learn: Make HTTP requests with HttpClient

    Official documentation · Confirmed on:

    Read on 20 November 2026: an HTTP proxy is set either by the static HttpClient.DefaultProxy (read from environment variables or system settings; on Linux with no variables it bypasses all addresses) or by the Proxy property of the handler, which overrides it; the HTTP_PROXY and HTTPS_PROXY URL may carry a username and password and must start with http, not https; the recommended approach is to reuse HttpClient instances during the application lifecycle; HttpClient.Timeout expiry raises TaskCanceledException with a TimeoutException inside; HttpRequestException carries StatusCode.

  2. Microsoft Learn: WebProxy class

    Official documentation · Confirmed on:

    Read on 20 November 2026: WebProxy contains the proxy settings HttpClient uses; it has an Address, a BypassList and a Credentials property for proxy authentication; the example builds an HttpClient from an HttpClientHandler whose Proxy is a WebProxy; a WebProxy built with the empty constructor has a null Address and uses no proxy.

  3. Microsoft Learn: SocketsHttpHandler.Proxy

    Official documentation · Confirmed on:

    Read on 20 November 2026: Proxy gets or sets the custom proxy when UseProxy is true.

  4. .NET blog: networking improvements in .NET 6

    Official documentation · Confirmed on:

    Read on 20 November 2026: .NET 6 added SOCKS4, SOCKS4a and SOCKS5 proxy support for HttpClient, enabled by using the socks scheme in the proxy definition; the post's example uses SocketsHttpHandler with a WebProxy for socks5://127.0.0.1:9050, and a footnote says the string constructor overload works only with HTTP proxies (fixed in .NET 7). The post does not say whether a SOCKS username and password are supported.

  5. Proxy302 product facts and price list

    Product observation · Confirmed on:

    Product facts file of the site, checked 20 November 2026 against the console and the price table: per-IP lease prices in US$ (1 PTC = US$1) for 1 to 90 days, HTTP port 2222 and SOCKS5 port 3333, quantity limit, no free trial, optional auto-renew.

Ready to try it?

Create an account, top up once, then pick rotating residential, static ISP or datacenter IPs and have one running in your browser within minutes.