Иногда я получаю сообщение об ошибке «неожиданное завершение потока при подключении» при вызове веб-службы с Android с использованием сервера go daddy и хостинга.
В часы пик мое приложение получает эту ошибку.
AppController.class
private void initRetrofitConfig() {
HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
interceptor.setLevel(BuildConfig.DEBUG ? HttpLoggingInterceptor.Level.BODY : HttpLoggingInterceptor.Level.NONE);
OkHttpClient client = new OkHttpClient.Builder()
.addInterceptor(interceptor)
.addInterceptor(new Interceptor() {
@Override
public Response intercept(Chain chain) throws IOException {
Request request = chain.request().newBuilder().addHeader("Connection", "close").build();
return chain.proceed(request);
}
})
.connectTimeout(30, TimeUnit.SECONDS)
.readTimeout(1, TimeUnit.MINUTES)
.writeTimeout(5, TimeUnit.MINUTES)
.retryOnConnectionFailure(true)
.build();
Retrofit retrofit = new Retrofit.Builder()
.client(client)
.baseUrl(SERVICE_URL)
.addConverterFactory(ScalarsConverterFactory.create())
.build();
apiEndpoint = retrofit.create(ApiEndpoint.class);
}
public ApiEndpoint getApiEndpoint() {
if (apiEndpoint == null) {
initRetrofitConfig();
}
return apiEndpoint;
}