package com.example.jinduer.di.okhttp;
import okhttp3.Callback;
import okhttp3.OkHttpClient;
import okhttp3.Request;
public class OKUtil {
private static OKUtil okUtil;
private final OkHttpClient okHttpClient;
//构造私有方法
public OKUtil(){
okHttpClient = new OkHttpClient.Builder()
//拦截器
.addInterceptor(new LogInterceptor())
.build();
}
public static OKUtil getInstance(){
if (null==okUtil){
synchronized (OKUtil.class){
if (null == okUtil){
return new OKUtil();
}
}
}
return okUtil;
}
public void get(String urlstring, Callback callback){
Request request = new Request.Builder().url(urlstring).build();
okHttpClient.newCall(request).enqueue(callback);
}
}
Android OKHTTP封装
最新推荐文章于 2024-07-15 10:16:22 发布