Use DefaultProxyCredentials for .NET HttpClient's Default Proxy
Use DefaultProxyCredentials for default discovery, WebProxy.Credentials for an explicit proxy and UseDefaultCredentials only for the destination server.
For the runtime's default proxy selection with the current security context:
var handler = new System.Net.Http.HttpClientHandler
{
UseProxy = true,
Proxy = null,
DefaultProxyCredentials =
System.Net.CredentialCache.DefaultCredentials
};
var client = new System.Net.Http.HttpClient(handler);DefaultProxyCredentials applies under the precise conditions shown: UseProxy = true and Proxy = null. The default policy still chooses the intermediary.
| Authentication recipient | Input |
|---|---|
| Default/discovered proxy | HttpClientHandler.DefaultProxyCredentials |
| Explicit WebProxy object | That object's Credentials |
| Destination server | HttpClientHandler.UseDefaultCredentials |
These similarly named inputs are not interchangeable. Set the handler before its first request and retain its client for the workload.
The proxy must accept the account through a scheme supported by both ends. A service's current identity can differ from the interactive user whose browser already works.