Skip to content

Instantly share code, notes, and snippets.

@Clans
Last active December 27, 2015 15:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Clans/7352013 to your computer and use it in GitHub Desktop.
Save Clans/7352013 to your computer and use it in GitHub Desktop.
Android: GET request
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