public class OkHttpUtils { private static final String TAG = "OkHttpUtils----"; private static OkHttpUtils okHttpUtils; private final OkHttpClient okHttpClient; private final Handler handler;
private OkHttpUtils() { HttpLoggingInterceptor httpLoggingInterceptor = new HttpLoggingInterceptor(); httpLoggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
HashMap<String, String> map = new HashMap<>(); PublicParamInterceptor paramInterceptor = new PublicParamInterceptor(map);
handler = new Handler(Looper.getMainLooper()); okHttpClient = new OkHttpClient.Builder() .connectTimeout(3000, TimeUnit.MILLISECONDS) .readTimeout(3000, TimeUnit.MILLISECONDS) .writeTimeout(3000, TimeUnit.MILLISECONDS) .addInterceptor(httpLoggingInterceptor) .addInterceptor(paramInterceptor) .build(); }
public static OkHttpUtils getInstance() { if (okHttpUtils == null) { synchronized (OkHttpUtils.class) { if (okHttpUtils == null) { return okHttpUtils = new OkHttpUtils(); } } } return okHttpUtils; }
public void doGet(String url, final OkHttpCallBack okCallBack) { final Request request = new Request.Builder() .get() .url(url) .build();
public class OkHttpUtils { private static final String TAG = "OkHttpUtils----"; private static OkHttpUtils okHttpUtils; private final OkHttpClient okHttpClient; private final Handler handl...