title: Authenticating a single request with httpclient 4.x
body: <p>I have an <code>HttpClient</code> instance that's shared by a number of threads. I would like to use it to make a single authenticated request. Because only the single request should be authenticated, I don't want to modify the <code>HttpClient</code> instance as described in the <a href="http://svn.apache.org/repos/asf/httpcomponents/httpclient/branches/4.0.x/httpclient/src/examples/org/apache/http/examples/client/ClientAuthentication.java" rel="nofollow noreferrer">documentation</a>.  Here's what I've worked out instead, which isn't working. From what I can tell, it doesn't look like the <code>CredentialsProvider</code> is being used at all. Any tips?</p>
  
  <pre><code>HttpContext context = null;
  if(feedSpec.isAuthenticated()) {
    context = new BasicHttpContext();
    CredentialsProvider credsProvider = new BasicCredentialsProvider();
    credsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(feedSpec.getHttpUsername(), feedSpec.getHttpPassword()));
    context.setAttribute(ClientContext.CREDS_PROVIDER, credsProvider);
    context.setAttribute(ClientPNames.HANDLE_AUTHENTICATION, true);
  }
  HttpGet httpGet = new HttpGet(feedSpec.getUri());
  HttpResponse httpResponse = httpClient.execute(httpGet, context);
  </code></pre>