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 内存管理研究


下一篇:android开发之第一个app程序