Advertisement
Guest User

Prelelele

a guest
Oct 30th, 2016
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.54 KB | None | 0 0
  1. public static void main(String args[]) throws MalformedURLException, IOException, JSONException{
  2.         String urlParameters  = "username=14650015&password=admin";
  3.         byte[] postData       = urlParameters.getBytes( StandardCharsets.UTF_8 );
  4.         int    postDataLength = postData.length;
  5.         String request        = "http://ios.pdef.space/auth.php";
  6.         URL    url            = new URL( request );
  7.         HttpURLConnection conn= (HttpURLConnection) url.openConnection();          
  8.         conn.setDoOutput( true );
  9.         conn.setInstanceFollowRedirects( false );
  10.         conn.setRequestMethod( "POST" );
  11.         conn.setRequestProperty( "Content-Type", "application/x-www-form-urlencoded");
  12.         conn.setRequestProperty( "charset", "utf-8");
  13.         conn.setRequestProperty( "Content-Length", Integer.toString( postDataLength ));
  14.         conn.setUseCaches( false );
  15.         try( DataOutputStream wr = new DataOutputStream( conn.getOutputStream())) {
  16.            wr.write( postData );
  17.            BufferedReader br = new BufferedReader(new InputStreamReader((conn.getInputStream())));
  18.             String output =br.readLine();
  19.             // Mendapatkan Hasil Dari JSON Standard
  20.             JSONObject json = new JSONObject(output);
  21.             // Membuat Object
  22.             //JSONObject presensi = json.getJSONObject("presensi");
  23.             // Membaca Data Latest Update
  24.             String message = json.getString("message");
  25.             System.out.print("Status Login : ");
  26.             System.out.println(message);
  27.         }
  28.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement