Java Utililty Methods HTTP Get

List of utility methods to do HTTP Get

Description

The list of methods to do HTTP Get are organized into topic(s).

Method

StringgetJsonFromUrl(String url)
get Json From Url
URL urll = new URL(url);
HttpURLConnection conn = (HttpURLConnection) urll.openConnection();
conn.setRequestMethod("GET");
conn.setRequestProperty("Accept", "application/json");
if (conn.getResponseCode() != 200) {
    throw new RuntimeException("Failed : HTTP error code : " + conn.getResponseCode());
BufferedReader br = new BufferedReader(new InputStreamReader((conn.getInputStream())));
...
StringhttpGet(String httpUrl)
http Get
BufferedReader input = null;
StringBuilder sb = null;
URL url = null;
HttpURLConnection con = null;
try {
    url = new URL(httpUrl);
    try {
        con = (HttpURLConnection) url.openConnection();
...
byte[]httpGet(String url)
http Get
try {
    URL obj = new URL(url);
    HttpURLConnection con = (HttpURLConnection) obj.openConnection();
    con.setRequestProperty("User-Agent", "Mozilla/5.0");
    InputStream in = con.getInputStream();
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    while (in.available() > 0)
        out.write(in.read());
...
StringhttpGet(String url, boolean logStdout)
Retrieve a text-based document using HTTP GET method.
May be used to retrieve XML documents, news feeds, etc.
final int bufferSize = 4096;
BufferedReader br = null;
HttpURLConnection urlc = null;
StringBuffer buffer = new StringBuffer();
URL page = new URL(url);
try {
    if (logStdout)
        System.err.println("Waiting for reply...:" + url);
...
inthttpGet(String url, StringBuffer response)
http Get
URL obj = new URL(url);
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
con.setRequestMethod("GET");
int responseCode = con.getResponseCode();
if (response != null && responseCode == 200 ) {
    try (BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()))) {
        String inputLine;
        while ((inputLine = in.readLine()) != null) {
...
StringhttpGet(String urlStr)
http Get
URL url = new URL(urlStr);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
if (conn.getResponseCode() != 200)
    throw new IOException(conn.getResponseMessage());
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
StringBuilder sb = new StringBuilder();
String line;
while ((line = rd.readLine()) != null)
...
StringhttpGet(String urlStr)
http Get
URL url = new URL(urlStr);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setDoOutput(true);
conn.connect();
return getHttpResponse(conn, 200);
StringhttpGet(String urlToRead)
Performs synchronous HTTP GET request, returns the response.
return httpGet(urlToRead, Proxy.NO_PROXY);
StringhttpGetString(String url)
http Get String
StringBuilder result = new StringBuilder();
HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection();
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();
ListreadUrl(final String strUrl)
read Url
final List<String> ret = new ArrayList<String>();
try {
    URL url = new URL(strUrl);
    HttpURLConnection c = (HttpURLConnection) url.openConnection();
    InputStream in = c.getInputStream();
    if (in != null) {
        StringBuilder sb = new StringBuilder();
        String line;
...