HttpClient的Get请求
2016-06-01 21:47
267 查看
//HttpClient的Get请求
private void getsubmit() {
private void getsubmit() {
new Thread() { public void run() { try { path = "http://apis.haoservice.com/lifeservice/travel/scenery?pid=2&cid=45&page=" + page + "&key=5ca4d84913684265948925e25468b409"; // 定义一个Http客户端对象 HttpClient httpClient = new DefaultHttpClient(); // 定义一个get请求的对象 HttpGet httpGet = new HttpGet(path); // 执行get请求,获取响应 HttpResponse httpResponse = httpClient.execute(httpGet); // 先获取状态行,再获取响应码 int statusCode = httpResponse.getStatusLine() .getStatusCode(); if (statusCode == 200) { // 请求成功 // 获取实体对象 HttpEntity entity = httpResponse.getEntity(); // 获取实体内容流 InputStream inputStream = entity.getContent(); String str = steamToStr(inputStream); Gson gson = new Gson(); Xin fromJson = gson.fromJson(str, Xin.class); Log.i("MainActivity", fromJson.result.get(0).address); al.addAll(fromJson.result); Message obtain = Message.obtain(); obtain.obj = fromJson; obtain.what = 1; handler.sendMessage(obtain); } } catch (Exception e) { e.printStackTrace(); } }; }.start(); }
相关文章推荐
- 网络图片+修改导航样式
- 网络判断
- httpurlconnection用于解析Json文件
- android中图片的三级缓存cache策略(内存/文件/网络)
- 网络远程教育平台课件实时记录学习时长的JS代码
- httputils及xlistview刷新
- TCP_NODELAY和Nagle算法
- 网络判断工具类
- netty 解决TCP粘包与拆包问题(三)
- java6.01学习笔记TCPServer
- Linux下的TCP/IP编程----进程及多进程服务端
- poj 1459(网络流)
- HttpURLConnection
- httpURLconnection
- XStream工具类解析XML
- 我的思科之路
- 一个Linux下的网络模拟工具 Core
- poj 3084(最小割)
- 进程—僵尸进程与孤儿进程
- python 网络客户端编程端口,模块