Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. public int getMeTheResponseCodeOfURL(final URL url) {
  2. HttpURLConnection httpUrlConnection = null;
  3. int statusCode = 0;
  4. String userName = "ABCD\michael";
  5. String userPass = "password!6789";
  6. String UserAndPass = userName + ":" + userPass;
  7. String userPassBase64 = Base64.getEncoder().encodeToString(UserAndPass.getBytes());
  8.  
  9. try {
  10. httpUrlConnection = (HttpURLConnection) url.openConnection();
  11. httpUrlConnection.setRequestProperty("Authorization", "Basic " + userPassBase64);
  12. httpUrlConnection.connect();
  13. statusCode = httpUrlConnection.getResponseCode();
  14.  
  15. } catch (final IOException e) {
  16. this.log.error("IO Exception! Errormessage: " + e);
  17. }
  18. return statusCode;
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement