Search in sources :

Example 1 with TimeAndDate

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);
}
Also used : HttpInfo(com.okhttplib.HttpInfo) Callback(com.okhttplib.callback.Callback) TimeAndDate(com.okhttp3.bean.TimeAndDate) Gson(com.google.gson.Gson) IOException(java.io.IOException)

Aggregations

Gson (com.google.gson.Gson)1 TimeAndDate (com.okhttp3.bean.TimeAndDate)1 HttpInfo (com.okhttplib.HttpInfo)1 Callback (com.okhttplib.callback.Callback)1 IOException (java.io.IOException)1