Created
December 3, 2014 00:44
-
-
Save ryanwarsaw/007f339975103ae85ec9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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