Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.