Android Emulator Support


In order to allow HTTP Debugger to decrypt SSL traffic from Android applications, you need to ignore SSL errors in DEBUG mode.
IMPORTANT: Make sure that you do this only in debug mode!

Define a helper function to disable certificate errors:

    private static void disableSSLCertificateErrors() {
        TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
            public X509Certificate[] getAcceptedIssuers() {
                return null;
            }

            @Override
            public void checkClientTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {
                // Not implemented
            }

            @Override
            public void checkServerTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {
                // Not implemented
            }
        } };

        try {
            SSLContext sc = SSLContext.getInstance("TLS");

            sc.init(null, trustAllCerts, new java.security.SecureRandom());

            HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
        } catch (KeyManagementException e) {
            e.printStackTrace();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
    }	
	

Call helper function before establishing a connection to the server:

    public static void getHTML() throws Exception {
        disableSSLCertificateErrors();

        StringBuilder result = new StringBuilder();
        URL url = new URL("https://www.google.com/");
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.setRequestMethod("GET");
        InputStream stream = conn.getInputStream();
        BufferedReader rd = new BufferedReader(new InputStreamReader(stream));
        String line;
        while ((line = rd.readLine()) != null) {
            result.append(line);
        }
        rd.close();
    } 
	

Result:

HTTP Debugger screenshot from Android Studio