Okhttp

OkHttp 連接https 出現Handshake failed

當server https的加密過舊並且不升級 我們前端可以利用兼容來解決(只支援到TLS1.0)

添加TLS1.0

val spec = ConnectionSpec.Builder(ConnectionSpec.COMPATIBLE_TLS)
     .tlsVersions(TlsVersion.TLS_1_0)
     .build()

val client = OkHttpClient.Builder()
     .connectionSpecs(Collections.singletonList(spec))
     .build()

或是判斷所有TLS和非Https

builder.connectionSpecs(
    listOf(
        ConnectionSpec.MODERN_TLS,
        ConnectionSpec.COMPATIBLE_TLS,
        ConnectionSpec.CLEARTEXT)
    )

運行結果

發表迴響