private void addAuthentication(HttpHost host, Credentials credentials,
            AuthScheme authScheme, HttpClientContext context) {
        AuthCache authCache = context.getAuthCache();
        if (authCache == null) {
            authCache = new BasicAuthCache();
            context.setAuthCache(authCache);
        }
        
        CredentialsProvider credsProvider = context.getCredentialsProvider();
        if (credsProvider == null) {
            credsProvider = new BasicCredentialsProvider();
            context.setCredentialsProvider(credsProvider);
        }
        
        credsProvider.setCredentials(new AuthScope(host), credentials);
        
        if (authScheme != null) {
            authCache.put(host, authScheme);
        }
    }
private void addAuthentication ( HttpHost host , Credentials credentials , AuthScheme authScheme , HttpClientContext context ) { AuthCache authCache = context . getAuthCache ( ) ; if ( authCache == null ) { authCache = new BasicAuthCache ( ) ; context . setAuthCache ( authCache ) ; } CredentialsProvider credsProvider = context . getCredentialsProvider ( ) ; if ( credsProvider == null ) { credsProvider = new BasicCredentialsProvider ( ) ; context . setCredentialsProvider ( credsProvider ) ; } credsProvider . setCredentials ( new AuthScope ( host ) , credentials ) ; if ( authScheme != null ) { authCache . put ( host , authScheme ) ; } }
Add authentication information for the given host
@param host the host
@param credentials the credentials
@param authScheme the scheme for preemptive authentication (should be
<code>null</code> if adding authentication for a proxy server)
@param context the context in which the authentication information
should be saved