6.53Configuring the Proxy Server

Created on Aug 17, 2026~1 min read

If you need to send requests through a proxy server, you can do so by configuring the Proxy property of HttpClientHandler. The following example shows how to configure a proxy server, including basic authentication.

cs
services.AddHttpClient(string.Empty, client => {})    .ConfigurePrimaryHttpMessageHandler(() =>        new HttpClientHandler   // or use new SocketsHttpHandler {}        {            Proxy = new WebProxy("http://proxyserver:8080", false)            {                Credentials = new NetworkCredential("username", "password") // if authentication is required            },            UseProxy = true // UseProxy is true by default; ensure it is enabled        });