Advertisement
The_red_Freak

Untitled

Apr 29th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.35 KB | None | 0 0
  1.  public static void makeAuthorization(String uuid, String username, String password) throws Exception{
  2.         URL apiurl = new URL(authAPI);
  3.         HttpURLConnection urlc = (HttpURLConnection) apiurl.openConnection();
  4.         urlc.setRequestMethod("POST");
  5. //        urlc.setRequestProperty("grant_type", "client_credentials");
  6.  
  7.         urlc.setDoInput(true);
  8.         urlc.setDoOutput(true);
  9.  
  10.         String ss = username + ":" + password;
  11.         String base = Base64.getEncoder().encodeToString(ss.getBytes());
  12.  
  13.         System.out.println(ss);
  14.         System.out.println(base);
  15.  
  16.         urlc.setRequestProperty("Authorization","Authorization: Basic " + base);
  17.  
  18. //        urlc.setRequestProperty("grant_type", "client_credentials");
  19.  
  20. //        String str =  "{\"grant_type\":\"client_credentials\"}";
  21. //        String str = "{\"Authorization\":\"Authorization: Basic " + base + "\"}";
  22.         String str = "grant_type:client_credentials";
  23.         byte[] outputInBytes = str.getBytes("UTF-8");
  24.         OutputStream os = urlc.getOutputStream();
  25.         os.write( outputInBytes );
  26.         os.close();
  27.  
  28.  
  29.         String inputstream = "";
  30.         Scanner s = new Scanner(urlc.getInputStream());
  31.         while (s.hasNextLine()){
  32.             inputstream += s.nextLine();
  33.         }
  34.         s.close();
  35.  
  36.         System.out.println(inputstream);
  37.  
  38.  
  39.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement