首页 > 移动平台 > 详细

Android 读取网络数据

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

通过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 读取网络数据

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!