title: HTTP Authentication for HttpURLConnection in Android
body: <p>My app needs to connect to multiple servers, each with their own username/password pairs. However The example provided in Android's javadoc does not consider multiple hosts with different sets of username/password:</p>
  
  <p><pre><code>
   Authenticator.setDefault(new Authenticator() {
       protected PasswordAuthentication getPasswordAuthentication() {
         return new PasswordAuthentication(username, password.toCharArray());<br>
     });
   }
  </pre></code></p>
  
  <p>This sets the VM-wide authentication handler, and has no way to identify which host we are trying to connect to. Is there a way that I can use HttpUrlConenction and handle HTTP Authentication with different user/passes for different hosts?</p>