title: Apache HttpClient not sending auth header when using credentials provider
body: <p>Edit: I have already tried the solutions provided in the comments and they don't work. Adding raw headers works, but I am trying to avoid doing that.</p>
  
  <p>I am facing a bizarre situation. I have a resource protected by basic auth which I am able to query easily via browser, Postman and curl. But in Java, I am not able to query it and getting a 403 forbidden error. I followed the below example:</p>
  
  <pre><code>CredentialsProvider provider = new BasicCredentialsProvider();
  UsernamePasswordCredentials credentials = new UsernamePasswordCredentials("username", "password");
  provider.setCredentials(AuthScope.ANY, credentials);
  CloseableHttpClient client = HttpClientBuilder.create().setDefaultCredentialsProvider(provider).build();
  
  HttpResponse response = client.execute(new HttpGet("https://hostname.com/api/detail?query=xx"));
  int statusCode = response.getStatusLine().getStatusCode();
  System.out.println(statusCode);     // prints 403 forbidden
  </code></pre>
  
  <p>When I inspected the objects in debugger, I noticed HttpGet object's headers were empty. That is, it wasn't passing the "Authorization" header with a "Basic asdflkhjWskjhakljhasdfkasdflkjh=" value.</p>
  
  <p>So I manually added the header with the correct value and it worked (status 200 OK).</p>
  
  <p>Can someone please help me figure out why this is happening and how can I use the HttpClient API to set the right headers instead of adding the header manually?</p>
  
  <p>This is my dependency:</p>
  
  <pre><code>&lt;groupId&gt;org.apache.httpcomponents&lt;/groupId&gt;
  &lt;artifactId&gt;httpclient&lt;/artifactId&gt;
  &lt;version&gt;4.5.3&lt;/version&gt;
  </code></pre>