Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static String AUTENTICATE_URL = "http://149.202.178.231/authenticate";
- public static String USERNAME = "-_-_-_-_-_-_";
- public static String PASSWORD = "-_-_-_-_-_-_";
- public static void main(String args[]) throws JSONException, MalformedURLException, IOException{
- URL url = new URL(AUTENTICATE_URL);
- HttpURLConnection con = (HttpURLConnection) url.openConnection();
- con.setDoOutput(true);
- con.setDoInput(true);
- con.setRequestProperty("Content-Type", "application/json");
- con.setRequestProperty("Accept", "application/json");
- con.setRequestMethod("POST");
- JSONObject auth = new JSONObject();
- auth.put("username", USERNAME);
- auth.put("password", PASSWORD);
- OutputStreamWriter wr = new OutputStreamWriter(con.getOutputStream());
- wr.write(auth.toString());
- wr.close();
- StringBuilder sb = new StringBuilder();
- int HttpResult = con.getResponseCode();
- if (HttpResult == HttpURLConnection.HTTP_OK){
- BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream(), "UTF-8"));
- String line = null;
- while ((line = br.readLine()) != null)sb.append(line + "\n");
- br.close();
- System.out.println("" + sb.toString());
- } else {
- System.out.println(con.getResponseMessage());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement