gpt4 book ai didi

android - Retrofit 2.3 无法在 8.0 设备上找到可接受的协议(protocol)

转载 作者:搜寻专家 更新时间:2023-11-01 09:31:16 24 4
gpt4 key购买 nike

我正在尝试让它在 Oreo 设备上运行。这在旧设备上非常有效,但在 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: <-- HTTP FAILED: java.net.UnknownServiceException: Unable to find acceptable protocols. isFallback=false, modes=[ConnectionSpec(cipherSuites=[TLS_DHE_RSA_WITH_AES_256_CBC_SHA], tlsVersions=[TLS_1_3], supportsTlsExtensions=true)], supported protocols=[TLSv1, TLSv1.1, TLSv1.2]

D/Error: Unable to find acceptable protocols. isFallback=false, modes=[ConnectionSpec(cipherSuites=[TLS_DHE_RSA_WITH_AES_256_CBC_SHA], tlsVersions=[TLS_1_3], supportsTlsExtensions=true)], supported protocols=[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();
}

最佳答案

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

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

关于android - Retrofit 2.3 无法在 8.0 设备上找到可接受的协议(protocol),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47111264/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com