BasicHttpContext localcontext = new BasicHttpContext();
if (isAuthConfigured) {
// Preemptive authentication enabled - see
// http://hc.apache.org/httpcomponents-client-ga/tutorial/html/authentication.html#d5e1032
HttpHost targetHost = new HttpHost(builder.getHost(), builder.getPort(), builder.getScheme());
AuthCache authCache = new BasicAuthCache();
BasicScheme basicAuth = new BasicScheme();
authCache.put(targetHost, basicAuth);
localcontext.setAttribute(ClientContext.AUTH_CACHE, authCache);
}
HttpResponse response = httpclient.execute(method, localcontext);
int statusCode = response.getStatusLine().getStatusCode();