【问题标题】:Retrofit 2.3 Unable to find acceptable protocols on 8.0 devicesRetrofit 2.3 无法在 8.0 设备上找到可接受的协议
【发布时间】:2018-04-17 02:24:14
【问题描述】:

我正在尝试让它在 Oreo 设备上运行。这在旧设备上完美运行,但在奥利奥上却不行。 我在握手时遇到问题,所以我添加了

ConnectionSpec spec = new ConnectionSpec.Builder(ConnectionSpec.MODERN_TLS)
   .tlsVersions(TlsVersion.TLS_1_2) 
   .cipherSuites(CipherSuite.TLS_DHE_RSA_WITH_AES_256_CBC_SHA)
   .build();

还有

   .connectionSpecs(Collections.singletonList(spec))

在客户端。 完整代码:

private static Retrofit getClient() {
    HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
    interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
    ConnectionSpec spec = new ConnectionSpec.Builder(ConnectionSpec.MODERN_TLS)
            .tlsVersions(TlsVersion.TLS_1_2)
            .cipherSuites(CipherSuite.TLS_DHE_RSA_WITH_AES_256_CBC_SHA)
            .build();

    OkHttpClient client = new OkHttpClient.Builder()
            .addInterceptor(interceptor)
            .connectionSpecs(Collections.singletonList(spec))
            .build();

    if (retrofit == null) {
        retrofit = new Retrofit.Builder()
                .baseUrl(BASE_URL)
                .addConverterFactory(GsonConverterFactory.create())
                .client(client)
                .build();
    }
    return retrofit;
}

但现在我遇到了错误

D/OkHttp:

D/错误:无法找到可接受的协议。 isFallback=false, 模式=[连接规范(密码套件=[TLS_DHE_RSA_WITH_AES_256_CBC_SHA], tlsVersions=[TLS_1_3],支持TlsExtensions=true)],支持 协议=[TLSv1, TLSv1.1, TLSv1.2]

有什么建议吗?

编辑 现在我已经这样做了,它可以工作。

if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            client = new OkHttpClient.Builder()
                    .addInterceptor(interceptor)
                    .build();
        }else {
            ConnectionSpec spec = new ConnectionSpec.Builder(ConnectionSpec.MODERN_TLS)
                    .tlsVersions(TlsVersion.TLS_1_2)
                    .cipherSuites(CipherSuite.TLS_DHE_RSA_WITH_AES_256_CBC_SHA)
                    .build();

            client = new OkHttpClient.Builder()
                    .addInterceptor(interceptor)
                    .connectionSpecs(Collections.singletonList(spec))
                    .build();
        }

【问题讨论】:

    标签: android retrofit2 okhttp android-8.0-oreo


    【解决方案1】:

    OkHttp 使用设备上启用的 TLS 版本与自己的连接规范的交集。密码套件也是如此。

    这里可能发生的情况是交集不包含您的网络服务器支持的任何内容。

    【讨论】:

    • 你的意思是我们需要根据客户端的交集来修改服务器部分,反之亦然。
    猜你喜欢
    • 2015-12-02
    • 2017-03-15
    • 1970-01-01
    • 2013-09-10
    • 2017-10-21
    • 2017-07-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多