package com.bw.day2_arouter;
import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;
public class RetrofitUtils {
private RetrofitUtils (){}
private static volatile RetrofitUtils retrofitUtils=null;
public static RetrofitUtils getInstance(){
if( retrofitUtils==null){
synchronized (RetrofitUtils.class){
if( retrofitUtils==null){
retrofitUtils = new RetrofitUtils();
}
}
}
return retrofitUtils;
}
public Retrofit getretrofit(){
OkHttpClient okHttpClient = new OkHttpClient.Builder()
.addInterceptor(new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY))
.build();
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("http://43.143.146.165:7777")
.client(okHttpClient)
.addConverterFactory(GsonConverterFactory.create())//转换成什么格式
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.build();
return retrofit;
}
}
专高三 day2 -RetrofitUtils单例
最新推荐文章于 2024-06-12 11:59:04 发布