Last active
December 10, 2015 18:18
-
-
Save mingcheng/4473364 to your computer and use it in GitHub Desktop.
在 Android 设备中发起 HTTP GET 请求
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
| 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