3

The below code works with HTTP(API version 7 and 8) and HTTPS (API version 7). For HTTPS (API version 8) I get error "java.io.IOException: SSL handshake failure: Failure in SSL library, usually a protocol error"

Any Idea why on version 8 alone ?

The code...

            HttpURLConnection connection = null;
            BufferedReader brd  = null;
            String line = "" ;
            StringBuilder sb = new StringBuilder();


            try {
                //Set up the initial connection
                //connection = (HttpURLConnection) new URL("http://MYSERVER.com").openConnection(); //Works
                connection = (HttpURLConnection) new URL("https://MYSERVER.com").openConnection(); //error
                connection.connect();

                    brd  = new BufferedReader(new InputStreamReader(connection.getInputStream()));
                    sb = new StringBuilder();
                    while ((line = brd.readLine()) != null)
                        sb.append(line);

                                  System.out.println(sb.toString());
       } catch (IOException e) {
                e.printStackTrace();
            }  finally{
                //close the connection, set all objects to null
                connection.disconnect();
                brd = null;
                sb = null;
                connection = null;
            }

The full error stack

WARN/System.err(267): java.io.IOException: SSL handshake failure: Failure in SSL library, usually a protocol error WARN/System.err(267): error:140773F2:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert unexpected message (external/openssl/ssl/s23_clnt.c:599 0xaf076ad8:0x00000000) at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.nativeconnect(Native Method) at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:316) at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.getSecureSocket(HttpConnection.java:168) at org.apache.harmony.luni.internal.net.www.protocol.https.HttpsURLConnectionImpl$HttpsEngine.connect(HttpsURLConnectionImpl.java:399) at org.apache.harmony.luni.internal.net.www.protocol.https.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:147)

Thanks, Narayanan

rekire
  • 47,260
  • 30
  • 167
  • 264
Narayanan
  • 163
  • 3
  • 10
  • 1
    Here is a solution http://stackoverflow.com/questions/2899079/custom-ssl-handling-stopped-working-on-android-2-2-froyo – Michael B. Aug 20 '10 at 20:19
  • user396259 Im facing the same problem http://stackoverflow.com/questions/9300821/ssl-not-working-on-android-2-2-only-in-2-3 Did you make it work? – CelinHC Feb 16 '12 at 11:24

0 Answers0