我正在尝试从TheMovieDatabase(TMDb)获取电影列表
获取:https://api.themoviedb.org/3/movie/now_playing?api_key= $ {KEY}&page = 1
但是,我得到以下信息:
HTTP失败:javax.net.ssl.SSLHandshakeException:连接被关闭 同行
以下是我已经尝试过的代码:
if (okHttpClient == null) {
ConnectionSpec spec = new ConnectionSpec.Builder(ConnectionSpec.COMPATIBLE_TLS) //tried MODERN_TLS also
.tlsVersions(TlsVersion.TLS_1_2)
.supportsTlsExtensions(true)
.cipherSuites(
CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
CipherSuite.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
CipherSuite.TLS_DHE_RSA_WITH_AES_128_GCM_SHA256
)
.build();
okHttpClient = new OkHttpClient.Builder()
.connectionSpecs(Collections.singletonList(spec))
.connectTimeout(30, TimeUnit.SECONDS)
.readTimeout(30, TimeUnit.SECONDS)
.addInterceptor(logging)
.build();
}
if (retrofit == null)
retrofit = new Retrofit.Builder()
.baseUrl(APIUtils.BASE_URL)
.client(okHttpClient)
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.addConverterFactory(GsonConverterFactory.create())
.build();
return retrofit;
}
日志:
javax.net.ssl.SSLHandshakeException:连接被同级关闭 在com.android.org.conscrypt.NativeCrypto.SSL_do_handshake(本机方法) 在com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:324) 在okhttp3.internal.connection.RealConnection.connectTls(RealConnection.java:318) 在okhttp3.internal.connection.RealConnection。EstablishmentProtocol(RealConnection.java:282) 在okhttp3.internal.connection.RealConnection.connect(RealConnection.java:167) 在okhttp3.internal.connection.StreamAllocation.findConnection(StreamAllocation.java:257) 在okhttp3.internal.connection.StreamAllocation.findHealthyConnection(StreamAllocation.java:135) 在okhttp3.internal.connection.StreamAllocation.newStream(StreamAllocation.java:114) 在okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:42) 在okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147) 在okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121) 在okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93) 在okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147) 在okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121) 在okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93) 在okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147) 在okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:126) 在okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147) 在okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121) 在okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:213) 在okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147) 在okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121) 在okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:200) 在okhttp3.RealCall.execute(RealCall.java:77) 在com.google.firebase.perf.network.FirebasePerfOkHttpClient.execute(未知 资源) 在retrofit2.OkHttpCall.execute(OkHttpCall.java:180) 在retrofit2.adapter.rxjava2.CallExecuteObservable.subscribeActual(CallExecuteObservable.java:42) 在io.reactivex.Observable.subscribe(Observable.java:12030) 在retrofit2.adapter.rxjava2.BodyObservable.subscribeActual(BodyObservable.java:34) 在io.reactivex.Observable.subscribe(Observable.java:12030) 在io.reactivex.internal.operators.observable.ObservableObserveOn.subscribeActual(ObservableObserveOn.java:45) 在io.reactivex.Observable.subscribe(Observable.java:12030) 在io.reactivex.internal.operators.observable.ObservableSubscribeOn $ SubscribeTask.run(ObservableSubscribeOn.java:96) 在io.reactivex.Scheduler $ DisposeTask.run(Scheduler.java:579) 在io.reactivex.internal.schedulers.ScheduledRunnable.run(ScheduledRunnable.java:66) 在io.reactivex.internal.schedulers.ScheduledRunnable.call(ScheduledRunnable.java:57) 在java.util.concurrent.FutureTask.run(FutureTask.java:237) 在java.util.concurrent.ScheduledThreadPoolExecutor $ ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:269) 在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113) 在java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:588) 在java.lang.Thread.run(Thread.java:818)