Hello Cyryl.

To connect you can do follow:

try {
                        SSLContext sc = SSLContext.getInstance("TLS");
                        sc.init(null, new TrustManager[] { new MyTrustManager() 
},
                                        new SecureRandom());
                        HttpsURLConnection
                                        
.setDefaultSSLSocketFactory(sc.getSocketFactory());
                        HttpsURLConnection
                                        .setDefaultHostnameVerifier(new 
MyHostnameVerifier());
                        HttpsURLConnection con = (HttpsURLConnection) new 
URL(HTTPS)
                                        .openConnection();
                        con.setDoOutput(true);
                        con.setDoInput(true);
                        con.connect();
}
catch (IOException e) {
                        System.err.println(e);
} catch (NoSuchAlgorithmException e) {
        // TODO Auto-generated catch block
                        e.printStackTrace();
                } catch (KeyManagementException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
}

//---------------------------------------------------------------------
public class MyHostnameVerifier implements HostnameVerifier {
        @Override
        public boolean verify(String arg0, SSLSession arg1) {
                // TODO Auto-generated method stub
                return true;
        }
}


//------------------------------------------------------

public class MyTrustManager implements X509TrustManager
{

    @Override
    public X509Certificate[] getAcceptedIssuers() {
            return null;
    }

        @Override
        public void checkClientTrusted(X509Certificate[] arg0,
                        String arg1) throws CertificateException {
                // TODO Auto-generated method stub

        }

        @Override
        public void checkServerTrusted(X509Certificate[] arg0,
                        String arg1) throws CertificateException {
                // TODO Auto-generated method stub

        }
}

On Oct 11, 11:14 pm, Cyryl Płotnicki-Chudyk <[email protected]>
wrote:
> I'm having trouble making https connection to the server , with
> password authentication.
> What is the simpliest & recommended way to do it ?

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to