我有一个用于网络连接的单例类。我希望超时增加,并编写了以下代码。
BizAnalystApiv2 provideBizAnalystApiV2(final ObjectMapper mapper) {
final HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
if (BuildConfig.DEBUG) {
logging.setLevel(HttpLoggingInterceptor.Level.BODY);
} else {
logging.setLevel(HttpLoggingInterceptor.Level.NONE);
}
final OkHttpClient client = new OkHttpClient.Builder()
.addInterceptor(logging)
.addInterceptor(new Interceptor() {
@Override
public Response intercept(Chain chain) throws IOException {
Request original = chain.request();
Request request = original.newBuilder()
.header("instanceId", FirebaseInstanceId.getInstance().getId())
.build();
return chain.proceed(request);
}
})
.readTimeout(70, TimeUnit.SECONDS)
.build();
return new Retrofit.Builder()
.addConverterFactory(JacksonConverterFactory.create(mapper))
.client(client)
.baseUrl(BizAnalystServicev2.getServerUrl())
.addCallAdapterFactory(RxJavaCallAdapterFactory.create())
.build()
.create(BizAnalystApiv2.class);
}
超时保持在15秒,这是默认超时。你能说明问题是什么吗?
我正在使用okhttp(v 3.4.1)和改装(v 2.1.0)