Sometimes I am getting error “unexpected end of stream on connection” while calling web service from android using go daddy server and hosting.
In pick hours my application got this error.
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;
}