generated from Java-2025Fall/final-vibevault-template
39 lines
1.5 KiB
Java
39 lines
1.5 KiB
Java
import java.io.BufferedReader;
|
|
import java.io.InputStreamReader;
|
|
import java.net.HttpURLConnection;
|
|
import java.net.URL;
|
|
|
|
public class TestApi {
|
|
public static void main(String[] args) {
|
|
try {
|
|
URL url = new URL("http://127.0.0.1:8081/api/playlists");
|
|
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
|
conn.setRequestMethod("GET");
|
|
conn.setRequestProperty("Content-Type", "application/json");
|
|
|
|
System.out.println("Sending GET request to: " + url.toString());
|
|
System.out.println("Connection timeout: " + conn.getConnectTimeout());
|
|
System.out.println("Read timeout: " + conn.getReadTimeout());
|
|
|
|
int responseCode = conn.getResponseCode();
|
|
System.out.println("Response Code: " + responseCode);
|
|
|
|
BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
|
|
String inputLine;
|
|
StringBuffer response = new StringBuffer();
|
|
|
|
while ((inputLine = in.readLine()) != null) {
|
|
response.append(inputLine);
|
|
}
|
|
in.close();
|
|
|
|
System.out.println("Response Body: " + response.toString());
|
|
conn.disconnect();
|
|
|
|
} catch (Exception e) {
|
|
System.out.println("Exception occurred: " + e.getClass().getName());
|
|
System.out.println("Exception message: " + e.getMessage());
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
} |