1

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;
}
Rumit Patel
  • 8,830
  • 18
  • 51
  • 70
  • check this https://stackoverflow.com/questions/45838774/java-io-ioexception-unexpected-end-of-stream-on-connection-in-android – VikaS GuttE Feb 22 '19 at 05:34

0 Answers0