title: Java 11 HttpClient not sending basic authentication
body: <p>I wrote the following HttpClient code, and it did not result in an <code>Authorization</code> header being sent to the server:</p>
  
  <pre><code>public static void main(String[] args) {
      var client = HttpClient.newBuilder()
              .authenticator(new Authenticator() {
                  @Override
                  protected PasswordAuthentication getPasswordAuthentication() {
                      return new PasswordAuthentication("username", "password".toCharArray());
                  }
              })
              .version(HttpClient.Version.HTTP_1_1)
              .build();
      var request = HttpRequest.newBuilder()
              .uri("https://service-that-needs-auth.example/")
              .build();
      client.sendAsync(request, HttpResponse.BodyHandlers.ofString())
              .thenApply(HttpResponse::body)
              .thenAccept(System.out::println)
              .join();
  }
  </code></pre>
  
  <p>I'm getting an HTTP 401 error from the service I'm calling. In my case, it's the Atlassian Jira Cloud API.</p>
  
  <p>I have confirmed that my <code>getPasswordAuthentication()</code> method is not being invoked by HttpClient.</p>
  
  <p>Why isn't it working, and what should I do instead?</p>