Skip to content

Instantly share code, notes, and snippets.

@pranaygp
Created September 13, 2015 10:05
Show Gist options
  • Save pranaygp/ca43ac3bcf5fba8f340f to your computer and use it in GitHub Desktop.
Save pranaygp/ca43ac3bcf5fba8f340f to your computer and use it in GitHub Desktop.
/**
* Made by Pranay Prakash <pranay.gp@gmail.com>
*/
public static String GET(String url){
InputStream inputStream = null;
String result = "";
try {
// create HttpClient
HttpClient httpclient = new DefaultHttpClient();
// make GET request to the given URL
HttpResponse httpResponse = httpclient.execute(new HttpGet(url));
// receive response as inputStream
inputStream = httpResponse.getEntity().getContent();
// convert inputstream to string
if(inputStream != null)
result = convertInputStreamToString(inputStream);
else
result = "Did not work!";
} catch (Exception e) {
Log.d("InputStream", e.getLocalizedMessage());
}
return result;
}
private static String convertInputStreamToString(InputStream inputStream) throws IOException{
BufferedReader bufferedReader = new BufferedReader( new InputStreamReader(inputStream));
String line = "";
String result = "";
while((line = bufferedReader.readLine()) != null)
result += line;
inputStream.close();
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment