public class HttpUtil {
private static HttpUtil instance;
private final Retrofit retrofit;
public static HttpUtil getInstance(){
if (instance==null){
instance=new HttpUtil();
}
return instance;
}
private HttpUtil(){
OkHttpClient okHttpClient = new OkHttpClient.Builder()
.readTimeout(60,TimeUnit.SECONDS)
.writeTimeout(60,TimeUnit.SECONDS)
.connectTimeout(60,TimeUnit.SECONDS)
.addInterceptor(new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY))
.build();
retrofit = new Retrofit.Builder()
.baseUrl("http://172.17.8.100/small/")
.client(okHttpClient)
.addConverterFactory(GsonConverterFactory.create())
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.build();
}
public <T> T create(final Class<T> service) {
return retrofit.create(service);
}
}