Back to Integrations
Developer Guide 10 Min Read

Using Turbo Proxy with C# HttpClient (.NET)

Comprehensive code examples for configuring WebProxy and HttpClientHandler in C# .NET to route all requests through Turbo Proxy residential and datacenter IPs.

C# HttpClient Proxy Configuration Mockup

C# HttpClient and Proxy Routing

The .NET HttpClient is the modern standard for sending HTTP requests in C# applications — from ASP.NET APIs and background services to console scrapers and automation tools. Routing HttpClient through a proxy is straightforward using HttpClientHandler and the built-in WebProxy class.

Turbo Proxy supports both HTTP/HTTPS and SOCKS5 protocols. For .NET 6+, native SOCKS5 support is built in via SocketsHttpHandler.


Prerequisites

  • .NET: version 6.0 or later (recommended)
  • Proxy Gateway: gate.turboproxy.online
  • Port: e.g., 7000
  • Username / Password: From your Turbo Proxy dashboard

Code Examples

Option A: HTTP Proxy with HttpClientHandler

using System;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;

class Program
{
    static async Task Main()
    {
        var proxy = new WebProxy("http://gate.turboproxy.online:7000")
        {
            Credentials = new NetworkCredential("your_username", "your_password")
        };

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

        using var client = new HttpClient(handler);
        var response = await client.GetStringAsync("https://api.ipify.org?format=json");
        Console.WriteLine(response);
    }
}

Option B: SOCKS5 Proxy (.NET 6+)

.NET 6 introduced native SOCKS5 support via SocketsHttpHandler:

using System;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;

class Program
{
    static async Task Main()
    {
        var handler = new SocketsHttpHandler
        {
            Proxy = new WebProxy("socks5://gate.turboproxy.online:7000")
            {
                Credentials = new NetworkCredential("your_username", "your_password")
            },
            UseProxy = true
        };

        using var client = new HttpClient(handler);
        var result = await client.GetStringAsync("https://api.ipify.org?format=json");
        Console.WriteLine(result);
    }
}

Option C: HttpClientFactory with DI (ASP.NET Core)

// In Program.cs or Startup.cs
builder.Services.AddHttpClient("proxied", client =>
{
    client.BaseAddress = new Uri("https://api.ipify.org");
})
.ConfigurePrimaryHttpMessageHandler(() => new HttpClientHandler
{
    Proxy = new WebProxy("http://gate.turboproxy.online:7000")
    {
        Credentials = new NetworkCredential("your_username", "your_password")
    },
    UseProxy = true
});

Troubleshooting

1. ProxyAuthenticationRequired (407)

Ensure you are passing NetworkCredential with your exact username and password. Avoid URL-encoding the credentials — pass them as separate strings to NetworkCredential.

2. SOCKS5 not working on .NET 5 or earlier

Native SOCKS5 support requires .NET 6+. On older versions, use a third-party library such as Starksoft.Aspen.Proxy or route through an HTTP proxy instead.

Route Your .NET Services Through Turbo Proxy

Get enterprise-grade residential proxies for your C# applications. Sign up and retrieve credentials in under 2 minutes.

Get Started Free