utils包
Api
public interface Api {
@GET("product/getProducts")
Call<GoodsBean> getData(@Query("pscid") String pscid,@Query("page") String page);
}
OkHttpUtils
public class OkHttpUtils {
private static OkHttpUtils okHttpUtils=null;
private final Retrofit retrofit;
public OkHttpUtils() {
OkHttpClient.Builder okHttpClient = new OkHttpClient.Builder();
okHttpClient.readTimeout(3000, TimeUnit.SECONDS);
okHttpClient.connectTimeout(3000,TimeUnit.SECONDS);
retrofit = new Retrofit.Builder()
.baseUrl(HttpConfig.URL)
.client(okHttpClient.build())
.addConverterFactory(GsonConverterFactory.create())
.build();
}
public static OkHttpUtils getInstance(){
if(null==okHttpUtils){
synchronized (OkHttpUtils.class){
if(null==okHttpUtils){
okHttpUtils=new OkHttpUtils();
}
}
}
return okHttpUtils;
}
public Api getApi(){
return retrofit.create(Api.class);
}
}