Guest User

Untitled

a guest
Nov 23rd, 2018
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. String username = "i4niac"
  2. String password = "mypassword"
  3.  
  4. // Create authorization header using Base64 encoding
  5. String userpass = username + ":" + password;
  6. String basicAuth = "Basic " + javax.xml.bind.DatatypeConverter.printBase64Binary(userpass.getBytes());
  7.  
  8. // Create URL
  9. URL url = branchesUrl.toURL()
  10.  
  11. // Open connection
  12. URLConnection connection = url.openConnection()
  13.  
  14. // Set authorization header
  15. connection.setRequestProperty ("Authorization", basicAuth)
  16.  
  17. // Open input stream
  18. InputStream inputStream = connection.getInputStream()
  19.  
  20. // Get JSON output
  21. def branchesJson = new groovy.json.JsonSlurper().parseText(inputStream.text)
  22.  
  23. // Close the stream
  24. inputStream.close()
Add Comment
Please, Sign In to add comment