I am using following dependencies (Retrofit and OkHttp).
implementation 'com.squareup.retrofit2:retrofit:2.3.0'
implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
implementation 'com.squareup.retrofit2:converter-scalars:2.3.0'
implementation 'com.squareup.okhttp3:okhttp:3.10.0'
implementation 'com.squareup.okhttp3:logging-interceptor:3.10.0'
Below is my code:
OkHttpClient okHttpClient = new OkHttpClient.Builder()
.addInterceptor(cache_interceptor)
.cache(cache)
.connectTimeout(AppConstants.TIME_OUT, TimeUnit.SECONDS)
.readTimeout(AppConstants.TIME_OUT, TimeUnit.SECONDS)
.writeTimeout(AppConstants.TIME_OUT, TimeUnit.SECONDS)
.connectionSpecs(Collections.singletonList(ConnectionSpec.CLEARTEXT))
.retryOnConnectionFailure(false)
.build();
return new Retrofit.Builder()
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.client(okHttpClient)
.addConverterFactory(ScalarsConverterFactory.create())
.addConverterFactory(GsonConverterFactory.create())
.baseUrl(BuildConfig.BASE_URL).build();
private final Interceptor cache_interceptor = new Interceptor() {
@Override
public Response intercept(Chain chain) throws IOException {
Request request = chain.request().newBuilder().addHeader("Connection", "close").build();
return chain.proceed(request);
}
};
The URL is https one, pointing to AWS S3 instance.
But I am getting following error for https
URL end point.
java.io.IOException: unexpected end of stream on Connection{s3.amazonaws.com:443, proxy=DIRECT hostAddress=s3.amazonaws.com/XX.XXX.XXX.XX:443 cipherSuite=none protocol=http/1.1}
Gone through similar threads like Github discussion 1 and Github discussion 2 but could not find a resolution.
If I replace https with http , there is no issue or error as well !!
Any idea what might be causing the problem?
EDIT 1:
As I was not sure what was causing the problem, I just commented out OK Http as client from Retrofit.
And surprisingly error was not thrown. !
return new Retrofit.Builder()
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.addConverterFactory(ScalarsConverterFactory.create())
.addConverterFactory(GsonConverterFactory.create())
.baseUrl(BuildConfig.BASE_URL).build();
Anyone wanna contribute to the issue, pls comment or write an answer. Much appreciable!