javax.net.ssl.SSLHandshakeExcept

2020-10-28  本文已影响0人  一个菜鸟JAVA

起因

在使用OkHttpClient的时候,请求https的接口,然后报下面的异常:

javax.net.ssl.SSLHandshakeException: Server chose TLSv1, but that protocol version is not enabled or not supported by the client.

看异常原因应该是客户端不支持TLSv1的协议导致的.

解决办法

这个原因主要是因为我本地版本为4.9.0,而在3.13.0就默认不再支持TLSv1了.修改起来也很简单,只需要在构建OkHttpClient的时候手动设置一下即可.

client = new OkHttpClient.Builder()
                .connectionSpecs(Collections.singletonList(ConnectionSpec.COMPATIBLE_TLS))
                .build();

资料

changelog

更新说明
上一篇下一篇

猜你喜欢

热点阅读