原因是由于服务器不被信任引起的
解决办法:
在 Application 的 onCreate 方法中调用下面方法即可
private fun handleSSLHandshake() { try { val trustAllCerts: Array<TrustManager> = arrayOf(object : X509TrustManager { override fun checkClientTrusted( chain: Array<out X509Certificate>?, authType: String? ) = Unit override fun checkServerTrusted( chain: Array<out X509Certificate>?, authType: String? ) = Unit override fun getAcceptedIssuers(): Array<X509Certificate> = arrayOf() }) val sc: SSLContext = SSLContext.getInstance("TLS") // trustAllCerts信任所有的证书 sc.init(null, trustAllCerts, SecureRandom()) HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()) HttpsURLConnection.setDefaultHostnameVerifier(object : HostnameVerifier { override fun verify(hostname: String?, session: SSLSession?): Boolean { return true } }) } catch (ignored: Exception) { } }