Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package JSon_Client;
- import java.io.BufferedReader;
- import java.io.InputStreamReader;
- import java.net.URL;
- import java.net.URLConnection;
- /**
- *
- * @author ferry
- */
- public class Hitung_Berat {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- try {
- // data json dalam bentuk string
- String json_data = "{\"nama\":\"ferry\",\"jkel\":\"pria\",\"tinggi\":170}";
- // Request HTTP GET ke server php(RestServer.php) dgn parameter p = isi dari variable "json_data"
- URL url = new URL("http://localhost/berat_ideal/RestServer.php?p="+json_data);
- URLConnection conn = url.openConnection();
- // Menampung Response dari request HTTP GET dalam bentuk tipe data BufferedReader (variable "rd")
- BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
- String line;
- System.out.println("URL GET REQUEST :\n"+url+"\n");
- // konversi dari BufferedReader(rd) ke dalam bentuk String(line), Agar data bisa di cetak oleh "System.out.println"
- while ((line = rd.readLine()) != null)
- {
- System.out.println(line);
- }
- //menutup response dari BufferedReader
- rd.close();
- } catch (Exception e) {
- //mencetak pesan error
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement