Created
September 13, 2015 10:05
-
-
Save pranaygp/ca43ac3bcf5fba8f340f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/** | |
* Made by Pranay Prakash <[email protected]> | |
*/ | |
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