Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void makeAuthorization(String uuid, String username, String password) throws Exception{
- URL apiurl = new URL(authAPI);
- HttpURLConnection urlc = (HttpURLConnection) apiurl.openConnection();
- urlc.setRequestMethod("POST");
- // urlc.setRequestProperty("grant_type", "client_credentials");
- urlc.setDoInput(true);
- urlc.setDoOutput(true);
- String ss = username + ":" + password;
- String base = Base64.getEncoder().encodeToString(ss.getBytes());
- System.out.println(ss);
- System.out.println(base);
- urlc.setRequestProperty("Authorization","Authorization: Basic " + base);
- // urlc.setRequestProperty("grant_type", "client_credentials");
- // String str = "{\"grant_type\":\"client_credentials\"}";
- // String str = "{\"Authorization\":\"Authorization: Basic " + base + "\"}";
- String str = "grant_type:client_credentials";
- byte[] outputInBytes = str.getBytes("UTF-8");
- OutputStream os = urlc.getOutputStream();
- os.write( outputInBytes );
- os.close();
- String inputstream = "";
- Scanner s = new Scanner(urlc.getInputStream());
- while (s.hasNextLine()){
- inputstream += s.nextLine();
- }
- s.close();
- System.out.println(inputstream);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement