oktatas:programozas:java:java_rest_api_kliens:httpurlconnection
Java REST API kliens
- Szerző: Sallai András
- Copyright © 2022, Sallai András
- Szerkesztve: 2022, 2023
- Licenc: CC BY-SA 4.0
- Web: https://szit.hu
Használatra példa
- Client.java
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; public class Client { public static void connect() throws IOException { URL url = new URL("https://jsonplaceholder.typicode.com/users/"); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("GET"); conn.connect(); InputStream is = conn.getInputStream(); InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr); StringBuffer sb = new StringBuffer(); String line = br.readLine(); while (line != null) { sb.append(line); sb.append(System.lineSeparator()); line = br.readLine(); } conn.disconnect(); System.out.println(sb.toString()); } }
oktatas/programozas/java/java_rest_api_kliens/httpurlconnection.txt · Utolsó módosítás: 2024/10/31 22:36 szerkesztette: admin