Android网络编程之通过Get方法实现
2011-05-17 22:28
549 查看
网络交互功能是Android的一个重要元素,Android是一款基于Linux的手机操作系统,同时具备Google的网络特性,今天介绍Android中通过Get方法实现网络交互,使用基于HTTP协议的Get方法来实现。
我们知道,要实现HTTP网络连接,都必须通过建立连接传输数据的基本步骤,下面我们对一个简单的例子稍做剖析。
A、创建URL实例
URL url = new URL("http://www.ataaw.com");
B、打开链接
URLConnection conn = url.openConnection();
C、获取返回码
int reCode = ((HttpURLConnection) conn).getResponseCode();
D、获取输入流
InputStream is = conn.getInputStream();
E、读取流内容
BufferedInputStream bis = new BufferedInputStream(is);
ByteArrayBuffer buffer = new ByteArrayBuffer(32);
int read = 0;
while ((read = bis.read()) != -1) {
buffer.append((char) read);
}
F、取出读到的字符串信息
EncodingUtils.getString(buffer.toByteArray(),HTTP.UTF_8);
本文出自 “android iOS” 博客,请务必保留此出处http://lovely1133.blog.51cto.com/1612511/567334
我们知道,要实现HTTP网络连接,都必须通过建立连接传输数据的基本步骤,下面我们对一个简单的例子稍做剖析。
A、创建URL实例
URL url = new URL("http://www.ataaw.com");
B、打开链接
URLConnection conn = url.openConnection();
C、获取返回码
int reCode = ((HttpURLConnection) conn).getResponseCode();
D、获取输入流
InputStream is = conn.getInputStream();
E、读取流内容
BufferedInputStream bis = new BufferedInputStream(is);
ByteArrayBuffer buffer = new ByteArrayBuffer(32);
int read = 0;
while ((read = bis.read()) != -1) {
buffer.append((char) read);
}
F、取出读到的字符串信息
EncodingUtils.getString(buffer.toByteArray(),HTTP.UTF_8);
本文出自 “android iOS” 博客,请务必保留此出处http://lovely1133.blog.51cto.com/1612511/567334
相关文章推荐
- Android 通过WebService进行网络编程,使用工具类轻松实现
- Android 通过get和post方法访问网络
- Android系列之网络(三)----使用HttpClient发送HTTP请求(分别通过GET和POST方法发送数据)
- Android 通过WebService进行网络编程,使用工具类轻松实现
- Android系列之网络(一)----使用HttpClient发送HTTP请求(通过get方法获取数据)
- Android低阶之【chapter - 6】Handler结合网络访问的使用方法,通过Handler实现异步网络请求
- Android之网络----使用HttpClient发送HTTP请求(通过get方法获取数据)
- 从零开始学android开发-通过WebService进行网络编程,使用工具类轻松实现
- Android系列之网络(三)----使用HttpClient发送HTTP请求(分别通过GET和POST方法发送数据)
- Android 通过WebService进行网络编程,使用工具类轻松实现
- Android之网络----使用HttpClient发送HTTP请求(通过get方法获取数据)
- Android 通过WebService进行网络编程,使用工具类轻松实现------客户端编程
- Android系列之网络(一)----使用HttpClient发送HTTP请求(通过get方法获取数据)
- Android联网app必用Get请求和Post请求的区别,网络编程代码实现
- Android 通过WebService进行网络编程,使用工具类轻松实现
- Android系列之网络(一)----使用HttpClient发送HTTP请求(通过get方法获取数据)
- Android系列之网络(一)----使用HttpClient发送HTTP请求(通过get方法获取数据)
- Android 通过WebService进行网络编程,使用工具类轻松实现
- Android通过HttpURLConnection和HttpClient接口实现网络编程
- android通过webservice进行网络编程,使用工具类实现