Android HttpUrlConnection上的javax.net.ssl.SSLHandshakeException

时间:2015-05-04 18:10:17

标签: java android ssl httpurlconnection sslhandshakeexception

我编写的代码可以登录并获取特定网站的HTML。

        String loginQuery = Sites.LOGIN_QUERY + "&member_no=" + id + "&password=" + pw;
        HttpsURLConnection con;

        con = (HttpsURLConnection) new URL(Sites.LOGIN_URL).openConnection();

        con.setRequestMethod("POST");
        con.setRequestProperty("Content-length", String.valueOf(loginQuery.length()));
        con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
        con.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0;Windows98;DigExt)");
        con.setDoOutput(true);
        con.setDoInput(true);

        // Exception in this line...
        DataOutputStream output = new DataOutputStream(con.getOutputStream());

        output.writeBytes(loginQuery);
        output.close();

问题是上面的代码运行良好但是在更新到android 5.0之后,发生了javax.net.ssl.SSLHandshakeException。我的设备以前的操作系统版本是4.4。

我在更新操作系统的过程中没有改变任何代码。我该如何解决这个问题?

异常日志:

05-05 14:54:08.821  10855-11793/com.soonoo.mobilecampus E/INFO﹕ javax.net.ssl.SSLHandshakeException: Handshake failed
        at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:374)
        at com.android.okhttp.Connection.upgradeToTls(Connection.java:238)
        at com.android.okhttp.Connection.connect(Connection.java:158)
        at com.android.okhttp.Connection.connect(Connection.java:170)
        at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:309)
        at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:242)
        at com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:388)
        at com.android.okhttp.internal.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:118)
        at com.android.okhttp.internal.http.HttpURLConnectionImpl.getOutputStream(HttpURLConnectionImpl.java:220)
        at com.android.okhttp.internal.http.DelegatingHttpsURLConnection.getOutputStream(DelegatingHttpsURLConnection.java:218)
        at com.android.okhttp.internal.http.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:25)
        at com.soonoo.mobilecampus.User.login(User.java:72)
        at com.soonoo.mobilecampus.LoginView$Login.doInBackground(LoginView.java:112)
        at com.soonoo.mobilecampus.LoginView$Login.doInBackground(LoginView.java:84)
        at android.os.AsyncTask$2.call(AsyncTask.java:288)
        at java.util.concurrent.FutureTask.run(FutureTask.java:237)
        at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
        at java.lang.Thread.run(Thread.java:818)
 Caused by: javax.net.ssl.SSLProtocolException: SSL handshake aborted: ssl=0xaaaf8a00: Failure in SSL library, usually a protocol error
error:1407743E:SSL routines:SSL23_GET_SERVER_HELLO:tlsv1 alert inappropriate fallback (external/openssl/ssl/s23_clnt.c:765 0xa9295b25:0x00000000)
        at com.android.org.conscrypt.NativeCrypto.SSL_do_handshake(Native Method)
        at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:302)
        ... 19 more

0 个答案:

没有答案