| | |
| | | package com.dayu.pipirrapp.net; |
| | | |
| | | |
| | | import com.dayu.pipirrapp.BuildConfig; |
| | | |
| | | import java.util.concurrent.TimeUnit; |
| | | |
| | | import okhttp3.OkHttpClient; |
| | |
| | | |
| | | private static RetrofitClient mInstance; |
| | | private final Retrofit retrofit; |
| | | private static final int READ_TIME_OUT = 10; |
| | | private static final int CONNECT_TIME_OUT = 10; |
| | | private static final int READ_TIME_OUT = 5; |
| | | private static final int CONNECT_TIME_OUT = 5; |
| | | |
| | | private RetrofitClient() { |
| | | HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor(); |
| | |
| | | // loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.HEADERS); |
| | | OkHttpClient.Builder builder = new OkHttpClient().newBuilder(); |
| | | //设置连接和读取时间 |
| | | builder.readTimeout(READ_TIME_OUT, TimeUnit.SECONDS); |
| | | builder.connectTimeout(CONNECT_TIME_OUT, TimeUnit.SECONDS); |
| | | builder.writeTimeout(CONNECT_TIME_OUT, TimeUnit.SECONDS); |
| | | builder.readTimeout(READ_TIME_OUT, TimeUnit.MINUTES); |
| | | builder.connectTimeout(CONNECT_TIME_OUT, TimeUnit.MINUTES); |
| | | builder.writeTimeout(CONNECT_TIME_OUT, TimeUnit.MINUTES); |
| | | //添加统一的header |
| | | builder.addInterceptor(new MyIntercepterApplication()); |
| | | //添加日志拦截器 |
| | | //添加数据请求统一处理拦截器 |
| | | // if (BuildConfig.DEBUG) { |
| | | builder.addInterceptor(loggingInterceptor); |
| | | // builder.addInterceptor(loggingInterceptor); |
| | | // } |
| | | |
| | | OkHttpClient client = builder.build(); |