gpt4 book ai didi

android - 在某些 Android 设备上握手失败

转载 作者:行者123 更新时间:2023-12-05 06:35:21 25 4
gpt4 key购买 nike

在某些设备上,与改造框架一起使用的服务器的通信没有问题。我还使用了几个 Android 版本来验证代码是否运行。但在某些设备(三星 S8)上,我每次都会收到错误消息:“握手失败”。有人知道问题出在哪里吗?谢谢!

这是我的代码:

protected static Retrofit getInstanceWithoutToken() {
final OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
httpClient.addInterceptor(new Interceptor() {
@Override
public okhttp3.Response intercept(Chain chain) throws IOException {
final Request original = chain.request();
final Request request = original.newBuilder()
.method(original.method(), original.body())
.build();
return chain.proceed(request);
}
});
return new Retrofit.Builder()
.baseUrl(CommonConstantsRest.REST_URL)
.addConverterFactory(GsonConverterFactory.create())
.client(httpClient.build())
.build();
}

最佳答案

问题出在 ssl 通信上。添加以下 CipherSuite 解决了问题

protected static Retrofit getInstanceWithoutToken() {
ConnectionSpec spec = new
ConnectionSpec.Builder(ConnectionSpec.MODERN_TLS)
.tlsVersions(TlsVersion.TLS_1_2)
.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();
final OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
logging.setLevel(HttpLoggingInterceptor.Level.BASIC);
httpClient.connectionSpecs(Collections.singletonList(spec));
httpClient
.addInterceptor(logging)
.addInterceptor(new Interceptor() {
@Override
public okhttp3.Response intercept(Chain chain) throws IOException {
final Request original = chain.request();
final Request request = original.newBuilder()
.method(original.method(), original.body())
.build();
return chain.proceed(request);
}
});
return new Retrofit.Builder()
.baseUrl(CommonConstantsRest.REST_URL)
.addConverterFactory(GsonConverterFactory.create())
.client(httpClient.build())
.build();
}

关于android - 在某些 Android 设备上握手失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49690403/

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