我使用Retrofit和OkHttp3来发出请求.我知道在
Android 4.4 TLS 1.1和TLS 1.2中没有启用defult.所以我想尝试启用它们.但到目前为止,我没有成功.我读到这可能是android工作室模拟器的一个问题,但是我无法在带有andoroid 4.4 rigthnow的真实设备上进行测试
这是我到目前为止所做的:
private S createService(Class serviceClass) {
Retrofit retrofit = builder.client(getNewHttpClient()).build();
return retrofit.create(serviceClass);
}
private OkHttpClient getNewHttpClient() {
OkHttpClient.Builder clientBuilder = new OkHttpClient.Builder()
.connectTimeout(10, TimeUnit.SECONDS)
.writeTimeout(10, TimeUnit.SECONDS)
.readTimeout(0, TimeUnit.MINUTES); // Disable timeouts for read
return enableTls12OnPreLollipop(clientBuilder).build();
}
public static OkHttpClient.Builder enableTls12OnPreLollipop(OkHttpClient.Builder client) {
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.KITK