Hi,

I am trying to make preemptive authentication in HttpClient 5 Async mode using 
the following code, but I does not work, first request is still without 
authentication and the authentication is done on the second request : 

        HttpClientContext httpContext = HttpClientContext.create();
        CredentialsProvider credentialsProvider = getCredentialsProvider();
        if (preemptive) {
                URI uri = URI.create(url);
                HttpHost targetHost = new HttpHost(uri.getScheme(), 
uri.getHost(), uri.getPort());
                AuthCache authCache = new BasicAuthCache();
                BasicScheme basicAuth = new BasicScheme();
                authCache.put(targetHost, basicAuth);
                httpContext.setAuthCache(authCache);
        }
        httpContext.setCredentialsProvider(credentialsProvider);

This code was working in httpClient 4. Any suggestion on how to make preemptive 
authentication work in HttpClient5 Async ?

Thank you,
Christophe



Reply via email to