.setTargetPreferredAuthSchemes(Arrays.asList(AuthSchemes.NTLM, AuthSchemes.DIGEST))
.setProxyPreferredAuthSchemes(Arrays.asList(AuthSchemes.BASIC))
.build();
// Create an HttpClient with the given custom dependencies and configuration.
CloseableHttpAsyncClient httpclient = HttpAsyncClients.custom()
.setConnectionManager(connManager)
.setDefaultCookieStore(cookieStore)
.setDefaultCredentialsProvider(credentialsProvider)
.setProxy(new HttpHost("myproxy", 8080))
.setDefaultRequestConfig(defaultRequestConfig)
.build();
try {
HttpGet httpget = new HttpGet("http://localhost/");
// Request configuration can be overridden at the request level.
// They will take precedence over the one set at the client level.
RequestConfig requestConfig = RequestConfig.copy(defaultRequestConfig)
.setSocketTimeout(5000)
.setConnectTimeout(5000)
.setConnectionRequestTimeout(5000)
.setProxy(new HttpHost("myotherproxy", 8080))
.build();
httpget.setConfig(requestConfig);
// Execution context can be customized locally.
HttpClientContext localContext = HttpClientContext.create();
// Contextual attributes set the local context level will take
// precedence over those set at the client level.
localContext.setCookieStore(cookieStore);
localContext.setCredentialsProvider(credentialsProvider);
System.out.println("Executing request " + httpget.getRequestLine());
httpclient.start();
// Pass local context as a parameter
Future<HttpResponse> future = httpclient.execute(httpget, localContext, null);
// Please note that it may be unsafe to access HttpContext instance
// while the request is still being executed
HttpResponse response = future.get();
System.out.println("Response: " + response.getStatusLine());
// Once the request has been executed the local context can
// be used to examine updated state and various objects affected
// by the request execution.
// Last executed request
localContext.getRequest();
// Execution route
localContext.getHttpRoute();
// Target auth state
localContext.getTargetAuthState();
// Proxy auth state
localContext.getTargetAuthState();
// Cookie origin
localContext.getCookieOrigin();
// Cookie spec used
localContext.getCookieSpec();
// User security token
localContext.getUserToken();
} finally {
httpclient.close();
}
}