0
因此,我試圖通過我的Android連接使用TLS v1.2(Let's Encrypt)的API https://api.ramein.id
。採用Android> 20時,但使用的是Android < 21 android的顯示器時無法使用Android中的Retrofit 2連接到HTTPS <21
一切工作正常說:
W/dalvikvm: VFY: unable to find class referenced in signature (Ljava/nio/file/Path;)
W/dalvikvm: VFY: unable to find class referenced in signature ([Ljava/nio/file/OpenOption;)
I/dalvikvm: Could not find method java.nio.file.Files.newOutputStream, referenced from method okio.Okio.sink
W/dalvikvm: VFY: unable to resolve static method 23633: Ljava/nio/file/Files;.newOutputStream (Ljava/nio/file/Path;[Ljava/nio/file/OpenOption;)Ljava/io/OutputStream;
D/dalvikvm: VFY: replacing opcode 0x71 at 0x000a
W/dalvikvm: VFY: unable to find class referenced in signature (Ljava/nio/file/Path;)
W/dalvikvm: VFY: unable to find class referenced in signature ([Ljava/nio/file/OpenOption;)
I/dalvikvm: Could not find method java.nio.file.Files.newInputStream, referenced from method okio.Okio.source
W/dalvikvm: VFY: unable to resolve static method 23632: Ljava/nio/file/Files;.newInputStream (Ljava/nio/file/Path;[Ljava/nio/file/OpenOption;)Ljava/io/InputStream;
D/dalvikvm: VFY: replacing opcode 0x71 at 0x000a
D/Error: java.net.ConnectException: Failed to connect to api.ramein.id/64:ff9b::8b3b:eb77:443
我從這裏實施的TLSSocketFactory https://gist.github.com/fkrauthan/ac8624466a4dee4fd02f
然後用它的東西像這樣:
httpClient = new OkHttpClient.Builder();
ConnectionSpec spec = new ConnectionSpec.Builder(ConnectionSpec.MODERN_TLS)
.tlsVersions(TlsVersion.TLS_1_2, TlsVersion.TLS_1_1)
.build();
if (Build.VERSION.SDK_INT < 21) {
X509TrustManager trustManager = TLSPatch.systemDefaultTrustManager();
httpClient.sslSocketFactory(new TLSPatch.TLSSocketFactory(), trustManager);
}
httpClient.connectionSpecs(Collections.singletonList(spec))
.readTimeout(60, TimeUnit.SECONDS);
有沒有人有這樣的問題?