Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The first thing you need to do is to set the level of verification. Such levels is not so much:</p> <ul> <li><strong>ALLOW_ALL_HOSTNAME_VERIFIER</strong></li> <li>BROWSER_COMPATIBLE_HOSTNAME_VERIFIER</li> <li>STRICT_HOSTNAME_VERIFIER</li> </ul> <p>Although the method setHostnameVerifier() is obsolete for new library apache, but for version in Android SDK is normal. And so we take <code>ALLOW_ALL_HOSTNAME_VERIFIER</code> and set it in the method factory <code>SSLSocketFactory.setHostnameVerifier()</code>.</p> <p>Next, You need set our factory for the protocol to https. To do this, simply call the <code>SchemeRegistry.register()</code> method.</p> <p>Then you need to create a <code>DefaultHttpClient</code> with <code>SingleClientConnManager</code>. Also in the code below you can see that on default will also use our flag (<code>ALLOW_ALL_HOSTNAME_VERIFIER</code>) by the method <code>HttpsURLConnection.setDefaultHostnameVerifier()</code></p> <p>Below code works for me:</p> <pre><code>HostnameVerifier hostnameVerifier = org.apache.http.conn.ssl.SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER; DefaultHttpClient client = new DefaultHttpClient(); SchemeRegistry registry = new SchemeRegistry(); SSLSocketFactory socketFactory = SSLSocketFactory.getSocketFactory(); socketFactory.setHostnameVerifier((X509HostnameVerifier) hostnameVerifier); registry.register(new Scheme("https", socketFactory, 443)); SingleClientConnManager mgr = new SingleClientConnManager(client.getParams(), registry); DefaultHttpClient httpClient = new DefaultHttpClient(mgr, client.getParams()); // Set verifier HttpsURLConnection.setDefaultHostnameVerifier(hostnameVerifier); // Example send http request final String url = "https://encrypted.google.com/"; HttpPost httpPost = new HttpPost(url); HttpResponse response = httpClient.execute(httpPost); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload