SSLHandshakeException:由peer关闭的连接

时间:2016-12-22 16:36:01

标签: android http jsoup

我有一个简单的代码,有一个例外,无法找出原因? 我的代码:

Document document= Jsoup.connect("https://kolkatatrafficpolice.net/").get();

堆栈追踪:

    javax.net.ssl.SSLHandshakeException: Connection closed by peer
W/System.err:     at com.android.org.conscrypt.NativeCrypto.SSL_do_handshake(Native Method)
W/System.err:     at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:357)
W/System.err:     at com.android.okhttp.Connection.connectTls(Connection.java:235)
W/System.err:     at com.android.okhttp.Connection.connectSocket(Connection.java:199)
W/System.err:     at com.android.okhttp.Connection.connect(Connection.java:172)
W/System.err:     at com.android.okhttp.Connection.connectAndSetOwner(Connection.java:367)
W/System.err:     at com.android.okhttp.OkHttpClient$1.connectAndSetOwner(OkHttpClient.java:130)
W/System.err:     at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:330)
W/System.err:     at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:247)
W/System.err:     at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:457)
W/System.err:     at com.android.okhttp.internal.huc.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:126)
W/System.err:     at com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.connect(DelegatingHttpsURLConnection.java:89)
W/System.err:     at com.android.okhttp.internal.huc.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java)
W/System.err:     at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:571)
W/System.err:     at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:548)
W/System.err:     at org.jsoup.helper.HttpConnection.execute(HttpConnection.java:235)
W/System.err:     at org.jsoup.helper.HttpConnection.get(HttpConnection.java:224)
W/System.err:     at com.pritesh.trafficviolation.GetHtml.doInBackground(MainActivity.java:29)

1 个答案:

答案 0 :(得分:0)

该服务器正在使用无法识别的证书颁发机构。

如果这是您的服务器,并且您有意这样做(例如,这是一个自签名证书),则需要配置JSoup / OkHttp以使用该自签名证书。

否则,您的问题在于服务器。