Skip to content

Instantly share code, notes, and snippets.

@mingcheng
Last active December 10, 2015 18:18
Show Gist options
  • Select an option

  • Save mingcheng/4473364 to your computer and use it in GitHub Desktop.

Select an option

Save mingcheng/4473364 to your computer and use it in GitHub Desktop.
在 Android 设备中发起 HTTP GET 请求
String response = "";
DefaultHttpClient client = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(url);
try {
HttpResponse execute = client.execute(httpGet);
InputStream content = execute.getEntity().getContent();
BufferedReader buffer = new BufferedReader(new InputStreamReader(content));
String s = "";
while ((s = buffer.readLine()) != null) {
response += s;
}
} catch (Exception e) {
e.printStackTrace();
}
return response;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment