原创禁止转载
xUtils是github上的一个Android开源工具项目,其中HttpUtils模块是处理网络连接部分,刚好最近想整理下Android网络编程知识,今天学习下xUtils中HttpUtils.
xUtils项目地址:(https://github.com/wyouflf/xUtils)
//下面是HttpUtils网络请求**注意倒包
//获取到HttpUtils
HttpUtils 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;
//重写请求失败的方法
@Override
public 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);
}
});