Code example for HttpsURLConnection

Methods: getSSLSocketFactorysetSSLSocketFactory

     * The standard HttpsURLConnection class will throw an exception on self 
     * signed certificates if this code is not run. 
    private static SSLSocketFactory trustAllHosts(HttpsURLConnection connection) {
        // Install the all-trusting trust manager 
        SSLSocketFactory oldFactory = connection.getSSLSocketFactory();
        try { 
            // Install our all trusting manager 
            SSLContext sc = SSLContext.getInstance("TLS");
            sc.init(null, trustAllCerts, new;
            SSLSocketFactory newFactory = sc.getSocketFactory();
        } catch (Exception e) {
            Log.e(LOG_TAG, e.getMessage(), e);
        return oldFactory;
    private static JSONObject createFileTransferError(int errorCode, String source, String target, URLConnection connection) {