当前位置首页 > Apache知识

android之ApacheHttp初使用——向服务器发送请求

阅读次数:206 次  来源:admin  发布时间:

//生成一个请求对象

HttpGet httpGet = new HttpGet("http://www.baidu.com")

//生成一个http客户端对象

HttpClient httpClient = new DefaultHttpClient()

//客户端向服务器发送请求,返回一个响应对象

HttpResponse httpResponse = httpClient.execute(httpGet)

//根据响应得到实体内容

HttpEntity entity = httpResponse.getEntity()

//使用IO流得到数据

InputStream inputStream = entity.getContent()

***注意:android sdk4.0不支持在主线程实现以上代码,需要创建新线程

上一篇:Fedora配置网络文件
下一篇:loongosn2f_龙芯灵珑9S2A一体机安装debian5和debian6双系统