Advertisement
Guest User

Untitled

a guest
Dec 2nd, 2016
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. public static String AUTENTICATE_URL = "http://149.202.178.231/authenticate";
  2. public static String USERNAME = "-_-_-_-_-_-_";
  3. public static String PASSWORD = "-_-_-_-_-_-_";
  4.  
  5. public static void main(String args[]) throws JSONException, MalformedURLException, IOException{
  6.  
  7. URL url = new URL(AUTENTICATE_URL);
  8.  
  9. HttpURLConnection con = (HttpURLConnection) url.openConnection();
  10. con.setDoOutput(true);
  11. con.setDoInput(true);
  12. con.setRequestProperty("Content-Type", "application/json");
  13. con.setRequestProperty("Accept", "application/json");
  14. con.setRequestMethod("POST");
  15.  
  16. JSONObject auth = new JSONObject();
  17.  
  18. auth.put("username", USERNAME);
  19. auth.put("password", PASSWORD);
  20.  
  21. OutputStreamWriter wr = new OutputStreamWriter(con.getOutputStream());
  22. wr.write(auth.toString());
  23. wr.close();
  24.  
  25. StringBuilder sb = new StringBuilder();
  26. int HttpResult = con.getResponseCode();
  27.  
  28. if (HttpResult == HttpURLConnection.HTTP_OK){
  29.  
  30. BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream(), "UTF-8"));
  31. String line = null;
  32. while ((line = br.readLine()) != null)sb.append(line + "\n");
  33. br.close();
  34. System.out.println("" + sb.toString());
  35. } else {
  36. System.out.println(con.getResponseMessage());
  37. }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement