Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Seems that you need to also set the hostname for your SSLSocketFactory.</p> <p>Try adding the line </p> <pre><code>socketFactory.setHostnameVerifier(SSLSocketFactory.STRICT_HOSTNAME_VERIFIER); </code></pre> <p>before creating a new connection with your <code>SSLFactory</code>.</p> <p>Other than the differences in structures, we have similar code. In my implementation I just created my own extension of the DefaultHttpClient which looks similar to the majority of your code above. If this doesn't fix it I can post the working code for that and you can give that approach a try.</p> <p>edit: here's my working version </p> <pre><code> public class ActivateHttpClient extends DefaultHttpClient { final Context context; /** * Public constructor taking two arguments for ActivateHttpClient. * @param context - Context referencing the calling Activity, for creation of * the socket factory. * @param params - HttpParams passed to this, specifically to set timeouts on the * connection. */ public ActivateHttpClient(Context context, HttpParams params) { this.setParams(params); } /* (non-Javadoc) * @see org.apache.http.impl.client.DefaultHttpClient#createClientConnectionManager() * Create references for both http and https schemes, allowing us to attach our custom * SSLSocketFactory to either */ @Override protected ClientConnectionManager createClientConnectionManager() { SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", PlainSocketFactory .getSocketFactory(), 80)); registry.register(new Scheme("https", newSslSocketFactory(), 443)); return new SingleClientConnManager(getParams(), registry); } /** * Creation of new SSLSocketFactory, which imports a certificate from * a server which self-signs its own certificate. * @return */ protected SSLSocketFactory newSslSocketFactory() { try { //Keystore must be in BKS (Bouncy Castle Keystore) KeyStore trusted = KeyStore.getInstance("BKS"); //Reference to the Keystore InputStream in = context.getResources().openRawResource( R.raw.cert); //Password to the keystore try { trusted.load(in, PASSWORD_HERE.toCharArray()); } finally { in.close(); } // Pass the keystore to the SSLSocketFactory. The factory is // responsible // for the verification of the server certificate. SSLSocketFactory sf = new SSLSocketFactory(trusted); // Hostname verification from certificate // http://hc.apache.org/httpcomponents-client-ga/tutorial/html/connmgmt.html#d4e506 sf.setHostnameVerifier(SSLSocketFactory.STRICT_HOSTNAME_VERIFIER); return sf; // return new SSLSocketFactory(trusted); } catch (Exception e) { e.printStackTrace(); throw new AssertionError(e); } } } </code></pre> <p>and can be called as shown : </p> <pre><code>HttpParams params = new BasicHttpParams(); // Set the timeout in milliseconds until a connection is established. int timeoutConnection = 500; HttpConnectionParams.setConnectionTimeout( params , timeoutConnection ); // Set the default socket timeout (SO_TIMEOUT) // in milliseconds which is the timeout for waiting for data. int timeoutSocket = 1000; HttpConnectionParams.setSoTimeout( params , timeoutSocket ); //ADD more connection options here! String url = "https:// URL STRING HERE"; HttpGet get = new HttpGet( url ); ActivateHttpClient client = new ActivateHttpClient( this.context, params ); // Try to execute the HttpGet, throwing errors // if no response is received, or if there is // an error in the execution. HTTPResponse response = client.execute( get ); </code></pre>
 

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