HttpUtils模块分析之网络请求

来源:互联网 发布:电子病历源代码pb源码 编辑:程序博客网 时间:2024/05/11 02:18

原创禁止转载

xUtils是github上的一个Android开源工具项目,其中HttpUtils模块是处理网络连接部分,刚好最近想整理下Android网络编程知识,今天学习下xUtils中HttpUtils.
xUtils项目地址:(https://github.com/wyouflf/xUtils)
//下面是HttpUtils网络请求**注意倒包

//获取到HttpUtilsHttpUtils httpUtils = new HttpUtils();//例子地址String path = "http://v.juhe.cn/laohuangli/h?date=2014-09-11&key=c546503135c95aeedb588a336f4453ed";httpUtils.send(HttpMethod.GET, path, new RequestCallBack<String>() {            private String result;//重写请求失败的方法@Overridepublic void onFailure(HttpException arg0, String arg1) {                String message = arg0.getMessage();                Log.i(TAG, "message" + message);Toast.makeText(MainActivity.this, "失败", 0).show();            }//重写请求成功的方法            @Override    public void onSuccess(ResponseInfo<String> info) {                result = info.result;    Toast.makeText(MainActivity.this, result, 0).show();                Log.i(TAG, "result" + result);            }        });
0 0
原创粉丝点击