import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; public class Main { public static void main(String[] args) throws IOException { } } private static String sendRequest(String urlString) throws IOException { URL url = new URL(urlString); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("GET"); BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); StringBuilder response = new StringBuilder(); String line; while ((line = reader.readLine()) != null) { response.append(line); } reader.close(); return response.toString(); } public static void main(String[] args) throws IOException { String url = "https://api.onebusaway.org/api/where/vehicles-for-agency/1.json?key=" + apiKey; String response = sendRequest(url); }


上一篇:
下一篇:
切换中文