码迷,mamicode.com
首页 > 移动开发 > 详细

Android 读取网络数据

时间:2014-06-05 08:30:08      阅读:226      评论:0      收藏:0      [点我收藏+]

标签:android   网络   数据   

通过HttpResponse  实现

首先在AndroidManifest中配置允许网络访问    

<uses-permissionandroid:name="android.permission.INTERNET"/>

然后实现代码

 

 示例代码如下

 

String url = "http://www.baidu.com";

HttpGet request = new HttpGet(url);

 

              try {

                     HttpResponseresponse = new DefaultHttpClient().execute(request);

                     HttpEntityentity = response.getEntity();

                     inputStream= entity.getContent();

                    

                     System.out.println("连接成功");

                     BufferedReaderreader = new BufferedReader(new InputStreamReader(inputStream));

                    

                     Stringline= "";

                     line= reader.readLine();

                     while(line!=null){

                           

                            System.out.println(line);

                            Line=reader.readLine();

 

}

                    

                    

                     System.out.println("下载结束");

Android 读取网络数据,布布扣,bubuko.com

Android 读取网络数据

标签:android   网络   数据   

原文地址:http://blog.csdn.net/lwjok2007/article/details/27334385

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!