Last active
December 27, 2015 15:59
-
-
Save Clans/7352013 to your computer and use it in GitHub Desktop.
Android: GET request
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
private static String makeGetRequest() throws IOException { | |
StringBuilder builder = new StringBuilder(); | |
HttpClient client = new DefaultHttpClient(); | |
HttpGet httpGet = new HttpGet(URL); | |
HttpResponse response = client.execute(httpGet); | |
StatusLine statusLine = response.getStatusLine(); | |
int statusCode = statusLine.getStatusCode(); | |
if (statusCode == 200) { | |
HttpEntity entity = response.getEntity(); | |
InputStream content = entity.getContent(); | |
BufferedReader reader = new BufferedReader(new InputStreamReader(content)); | |
String line; | |
while ((line = reader.readLine()) != null) { | |
builder.append(line); | |
} | |
} | |
reader.close(); | |
return builder.toString(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment