Pull解析xml文件,并用HttpUtils请求数据接口(示例方法)
2016-06-30 20:27
671 查看
public void httputils()
{
String path="http://www.oschina.net/action/api/news_list?catalog=1&pageSize=20&pageIndex"+pageIndex;
HttpUtils utils=new HttpUtils();
utils.send(HttpMethod.GET, path, new RequestCallBack<String>() {
@Override
public void onFailure(HttpException arg0, String arg1) {
System.out.println("请求失败"+arg1);
}
@Override
public void onSuccess(ResponseInfo<String> arg0) {
String str=arg0.result;
// Log.i("TAG", str);
//字节输入流
ByteArrayInputStream bs=new ByteArrayInputStream(str.getBytes());
//创建对象
RequestData requestData=new RequestData();
//得到字节流
list = requestData.parse(bs);
Message msg=Message.obtain();
//将集合给obj
msg.obj=list;
//给定一个标志
msg.what=1;
//利用handler发送消息
handler.sendMessage(msg);
}
});
}
{
String path="http://www.oschina.net/action/api/news_list?catalog=1&pageSize=20&pageIndex"+pageIndex;
HttpUtils utils=new HttpUtils();
utils.send(HttpMethod.GET, path, new RequestCallBack<String>() {
@Override
public void onFailure(HttpException arg0, String arg1) {
System.out.println("请求失败"+arg1);
}
@Override
public void onSuccess(ResponseInfo<String> arg0) {
String str=arg0.result;
// Log.i("TAG", str);
//字节输入流
ByteArrayInputStream bs=new ByteArrayInputStream(str.getBytes());
//创建对象
RequestData requestData=new RequestData();
//得到字节流
list = requestData.parse(bs);
Message msg=Message.obtain();
//将集合给obj
msg.obj=list;
//给定一个标志
msg.what=1;
//利用handler发送消息
handler.sendMessage(msg);
}
});
}
相关文章推荐
- linux --- TCPdump 工具
- hdu_3549_Flow Problem(最大流)
- 移动开发----网络解析xml
- VMware 虚拟机下网络参数配置
- Canvase 绘制圆图,用于请求网络数据
- HttpUtils 请求数据(json)
- HttpUtils 请求数据(pull)
- HTTP协议头——Content-MD5
- httpclient请求数据和gson的解析
- 使用 Charles 获取 https 的数据
- Android下载网络图片,ImageView读取本地图片
- 用NSURLSession发送网络请求
- 神经网络优化算法选择
- HtmlUnit--java网络爬虫
- 第三方的httputils请求数据和xml的pull解析
- 利用bluebird的promise 实现nodejs http下载异步调用的同步逻辑
- Wireshark分析TCP连接建立过程
- DNS工作原理-----简述
- Flex远程访问获取数据--HTTPService
- Redheat配置网络yum源