發表文章

目前顯示的是 3月, 2019的文章

政府與android 的互鬥: android 9 SSLHandshakeException: Handshake failed

圖片
From Android 9 Pie now, requests without encryption will never work. And by default, the System will expect you to use TLS by default. 簡單講就是:android 9.0後一定要用https, 偏偏政府機構的ssl憑證有問題, 但政府機構不承認他們有問題...所以opendata 資料會取不到. 可說是政府與android的互鬥. OkHttp或 urlconnect 報錯javax.net.ssl.SSLHandshakeException: Handshake failed error message: Failure in SSL library, usually a protocol errorerror:100000f0:SSL routines:OPENSSL_internal:UNSUPPORTED_PROTOCOL problem: Error when connecting from Android to a server that does not support TLS 1.0 solution step 1:   OkHttpClient client = new OkHttpClient.Builder() .connectionSpecs(Arrays.asList(ConnectionSpec.COMPATIBLE_TLS)) .build();   Request request = new Request.Builder() .url( url ) .build(); Response responses = null ; responses = client.newCall(request).execute(); return responses.body().string(); but got another error: javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust an