Use a residential proxy in C# with HttpClient: WebProxy and a first check

Configure C# with HttpClient with separate residential proxy host and credentials, then run one authorized request. Includes fake placeholders, checks, and troubleshooting.

Configure C# with HttpClient with separate residential proxy host and credentials, then run one authorized request. Includes fake placeholders, checks, and troubleshooting.

This guide connects C# with HttpClient to a residential proxy and verifies one authorized request. Copy the actual protocol, host, port, username, and password from the console. The values below are deliberately fake: host `proxy.example.invalid`, port `10000`, username `USER_EXAMPLE`, password `PASS_EXAMPLE_NOT_REAL`. Not for mainland China.

Choose rotating residential for changing exits and traffic billing, or static residential when one exit must stay fixed for the order term. A sticky session is not a static IP.

Map the console fields

Console valueExampleWhere it goes
ProtocolHTTPThe proxy URL scheme or client proxy type
Host and port`proxy.example.invalid` and `10000`The gateway address, without credentials
Username and password`USER_EXAMPLE` and `PASS_EXAMPLE_NOT_REAL`Separate authentication fields

Create a `WebProxy` from host and port only, then set its `Credentials` to a separate `NetworkCredential`. Pass it to `HttpClientHandler`.

Minimal example

using System.Net;

var proxy = new WebProxy("http://proxy.example.invalid:10000")
{
    Credentials = new NetworkCredential("USER_EXAMPLE", "PASS_EXAMPLE_NOT_REAL")
};

using var handler = new HttpClientHandler { Proxy = proxy, UseProxy = true };
using var client = new HttpClient(handler) { Timeout = TimeSpan.FromSeconds(30) };
using var response = await client.GetAsync("https://example.com/");
Console.WriteLine((int)response.StatusCode);

Reuse HttpClient in long-running applications. Creating one per request can exhaust sockets and makes proxy failures harder to diagnose. The target in the snippet is only a connectivity placeholder; replace it with a page you are authorized to access. For a source-IP check, use an approved endpoint that displays the request IP.

First-check sequence

ResultMeaningNext step
2xx or expected target responseThe route workedConfirm the observed exit and region
HTTP 407Proxy authentication failedRe-copy auth; do not move credentials into the host
Timeout / connection refusedRoute, protocol, port, firewall, or target issueCompare with curl testing and use a finite timeout
Unexpected region or changing exitSelection or session mismatchCheck the console parameters; use static if the order term needs one IP

For field shapes, see proxy format, HTTP / SOCKS5 setup, Docs quickstart, and 407 / timeout troubleshooting.

FAQ

What does HTTP 407 mean?

The gateway reached your client but rejected or did not receive proxy authentication. Re-copy the username and password from the console and keep them in the authentication fields.

Why does the request time out?

Check protocol, host, port, local firewall, DNS, and the authorized target. Then reduce the test to one request with a finite timeout.

Should the host include the protocol?

No. Keep the host as a hostname. Add the scheme only where the library expects a proxy URL.

Can I use SOCKS5 with this exact example?

Not necessarily. This C# with HttpClient example demonstrates an HTTP proxy. Use the protocol returned by the console and the library-specific SOCKS adapter when required.

How do I confirm the exit?

Request an authorized page that reports the source IP, compare it with your intended region or static order, and do not treat a gateway hostname as the exit.

Can a sticky session replace a static IP?

No. Sticky keeps a rotating exit for a limited window when available; a static residential order keeps its assigned exit for the order term.

May I use these placeholder credentials?

No. The example domain cannot resolve and every credential shown here is fake. Copy current values from the console.

Can I use this in mainland China?

No. ZTProxy proxy services are not supported for use in mainland China. Use only lawful, authorized targets.

Next steps

  1. Copy the current gateway and auth from the console.
  2. Run the example against one authorized target.
  3. Confirm the exit, then add retries and concurrency gradually. Compare other clients: Python, Node.js and Axios, and PHP and Guzzle.