简体   繁体   中英

Self Signed SSL Connection - Android

I added the SSLFactory and the TrustManager classes as described here .

I'm establishing a connection as following:

//does not work
String url = "https://waprd.uark.edu/web-apps/regr/scheduleofclasses/Main?strm=1123";
  //http://bektemirov.com/a/android.php?t=amurica   //simple http - works

HttpClient client = new DefaultHttpClient(clientConnectionManager, params);
HttpGet get = new HttpGet(url);
try {
  HttpResponse response = client.execute(get, context);
  HttpEntity entity = response.getEntity();

  String responseText = EntityUtils.toString(entity);
  Body.setText(responseText);

} catch (ClientProtocolException e) {
  // TODO Auto-generated catch block
  e.printStackTrace();
} catch (IOException e) {
  // TODO Auto-generated catch block
  e.printStackTrace();
}

Connection fails every time for this particular link. Direct me in the right direction, please?

When you initialize SSLContext, there is a parameter to pass TrustManager array where you can define your own TrustManager to accept all. Some of the key steps are listed below :

  1. Subclass SSLSocketFactory

  2. Customize TrustManager to accept all certificates in subclass of SSLSocketFactory.

  3. Initialize SSLContext with the customized TrustManager in subclass of SSLSocketFactory.

  4. Create parameterized DefaultHttpClient with HttpParams and ClientConnectionManager which uses SchemeRegistry where you can register 'https' with your subclass of SSLSocketFactory.

So that, all https response will be handled by your customized TrustManager class.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM