Here you can find the source of getResponse(URL url)
Parameter | Description |
---|---|
url | a parameter |
Parameter | Description |
---|---|
IOException | an exception |
public static String getResponse(URL url) throws IOException
//package com.java2s; //License from project: Apache License import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; public class Main { private static final String URL = "URL"; private static final String GET = "GET"; /**//from w w w . j a va 2s. co m * Returns the content of the response body for the given url * * @param url * @return the content of the response body * @throws IOException */ public static String getResponse(URL url) throws IOException { StringBuffer response = new StringBuffer(); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod(GET); try (BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream()))) { String sCurrentLine; while ((sCurrentLine = br.readLine()) != null) { response.append(sCurrentLine); } } return response.toString(); } }