use of com.okhttp3.bean.TimeAndDate in project OkHttp3 by MrZhousf.
the class MainActivity method async.
/**
* 异步请求:回调方法可以直接操作UI
*/
private void async() {
OkHttpUtil.getDefault(this).doGetAsync(HttpInfo.Builder().setUrl(url).addHead("head", //添加头参数
"test").addParam("param", //添加接口参数
"test").build(), new Callback() {
@Override
public void onFailure(HttpInfo info) throws IOException {
String result = info.getRetDetail();
resultTV.setText("异步请求失败:" + result);
}
@Override
public void onSuccess(HttpInfo info) throws IOException {
String result = info.getRetDetail();
resultTV.setText("异步请求成功:" + result);
//GSon解析
TimeAndDate time = new Gson().fromJson(result, TimeAndDate.class);
LogUtil.d("MainActivity", time.getResult().toString());
setFromCacheTV(info);
}
});
needDeleteCache(true);
}
Aggregations