Advertisement
Guest User

Untitled

a guest
Oct 24th, 2016
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. static class MyAuthenticator extends Authenticator {
  2. public PasswordAuthentication getPasswordAuthentication() {
  3. System.out.println("trying to authenticate");
  4. return new PasswordAuthentication("user", "password".toCharArray());
  5. }
  6. }
  7.  
  8. Authenticator.setDefault(new MyAuthenticator())
  9.  
  10. String encoding = Base64.encode("user:password".getBytes());
  11. HttpURLConnection connection = (HttpURLConnection) url.openConnection();
  12. connection.setRequestMethod("GET");
  13. connection.setDoOutput(true);
  14. connection.setRequestProperty ("Authorization", "Basic " + encoding);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement