Skip to content

HttpClient With Proxy did not handle the Proxy 407 auth flow on Linux OS #105724

Open

Description

Description

Hi,
I`m developing an application which using HttpClient with HttpClientHandler to manage my Http network connection.
While setting my WebProxy on the HttpClientHandler I getting errors of 407 although my Proxy credentials are correct.

see a code snip:

foo(Uri? iProxyUri, NetworkCredential iProxyCredentials){
       CredentialCache cache = [];
       
       _ = cache.TryAdd(iProxyUri, iProxyCredentials);
        
         HttpClientHandler handler = new()
        {
            AllowAutoRedirect = false, // we want to handle the redirect 
            ServerCertificateCustomValidationCallback = (iRequest,
                                                         _1,
                                                         _2,
                                                         iErrors) => true,
            Proxy = new WebProxy(iProxyUri, false)
            {
                Credentials = iProxyCredentials,
                UseDefaultCredentials = false
            },
            SslProtocols = MySslProtocol,
            UseProxy = true,
            DefaultProxyCredentials = cache,
            Credentials = cache,
            UseDefaultCredentials = false,
            // PreAuthenticate = true
        };
        using HttpClient client = new(handler)
        {
            Timeout = TimeSpan.FromMinutes(5)
        };
}

Reproduction Steps

  1. Create HttpClient with HttpClientHandler which contains proxy that require username and password .
  2. Make API call to https://example.com

Expected behavior

407 response will be handle by the client handler and credentials should pass to the proxy server

Actual behavior

Received 407 response although client handler contains the proxy credentials

Regression?

Yes, I have an application with more or less the same code that running on .net 6 and I don`t see this issue there

Known Workarounds

No response

Configuration

No response

Other information

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions