1.添加依赖
implementation 'com.squareup.okhttp3:okhttp:3.2.0'
implementation 'com.squareup.okio:okio:1.7.0'
implementation 'com.squareup.okhttp3:logging-interceptor:3.4.1'
implementation 'com.squareup.retrofit2:retrofit:2.0.0'
implementation 'com.squareup.retrofit2:converter-gson:2.0.2'
2.封装工具类
public class RetrofitUtils {
private static RetrofitUtils retrofitUtils;
private RetrofitUtils(){}
public static RetrofitUtils getInstance(){
if (retrofitUtils==null){
synchronized (RetrofitUtils.class){
if (retrofitUtils==null){
retrofitUtils=new RetrofitUtils();
}
}
}
return retrofitUtils;
}
private static OkHttpClient okHttpClient;
private static synchronized OkHttpClient getOkHttpClient() {
final HttpLoggingInterceptor loggingInterc