Skip to content

Instantly share code, notes, and snippets.

@ryanwarsaw
Created December 3, 2014 00:44
Show Gist options
  • Save ryanwarsaw/007f339975103ae85ec9 to your computer and use it in GitHub Desktop.
Save ryanwarsaw/007f339975103ae85ec9 to your computer and use it in GitHub Desktop.
package me.ryanw.launch.me.ryanw.utils;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
public class RESTful {
public static String httpGet(String urlString) throws IOException {
URL url = new URL(urlString);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
if (connection.getResponseCode() != 200) {
throw new IOException(connection.getResponseMessage());
}
BufferedReader read = new BufferedReader (new InputStreamReader(connection.getInputStream()));
StringBuilder stringBuilder = new StringBuilder();
String line;
try {
while ((line = read.readLine()) != null) {
stringBuilder.append(line);
}
} catch(IOException e) {
e.printStackTrace();
}
read.close();
connection.disconnect();
return stringBuilder.toString();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment