Here you can find the source of httpGet(String urlToRead)
Parameter | Description |
---|---|
urlToRead | a parameter |
Parameter | Description |
---|---|
Exception | an exception |
public static String httpGet(String urlToRead) throws Exception
//package com.java2s; //License from project: Open Source License import java.io.BufferedReader; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.Proxy; import java.net.URL; public class Main { /**/*from w w w . j av a 2 s. c o m*/ * Performs synchronous HTTP GET request, returns the response. * * @param urlToRead * @return * @throws Exception */ public static String httpGet(String urlToRead) throws Exception { return httpGet(urlToRead, Proxy.NO_PROXY); } public static String httpGet(String urlToRead, Proxy proxy) throws Exception { StringBuilder result = new StringBuilder(); URL url = new URL(urlToRead); HttpURLConnection conn = (HttpURLConnection) url.openConnection(proxy); conn.setRequestMethod("GET"); BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream())); String line; while ((line = rd.readLine()) != null) { result.append(line); } rd.close(); return result.toString(); } }