public class RetrofitUtils { public static MainAPi mainAPi; public static RetrofitUtils retrofitUtils; public RetrofitUtils() { OkHttpClient builder = new OkHttpClient.Builder() .addInterceptor(new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY)) .build(); Retrofit retrofit = new Retrofit.Builder() .baseUrl(Contanx.URL) .addConverterFactory(GsonConverterFactory.create()) .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) .client(builder) .build(); mainAPi = retrofit.create(MainAPi.class); } public static RetrofitUtils getInstance(){ if (retrofitUtils == null){ retrofitUtils = new RetrofitUtils(); } return retrofitUtils; } public MainAPi api(){ return mainAPi; } }
rxJava+Retrofit工具类
最新推荐文章于 2021-05-28 21:34:57 发布