1

I have some difficulties with using ssl on Android 2.2 My custom Http client for ssl work finly on earlier and older versions of Android, but on 2.2 https requests don't run att all. Here my code:

public class SSLHttpClient extends DefaultHttpClient {

    final Context context;

    public SSLHttpClient(Context context,HttpParams params) {
        super(params);
        this.context = context;
    }

    @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);
    }

    private SSLSocketFactory newSslSocketFactory() {
        try {           
            SSLSocketFactory sf = new SSLSocketFactory(keyStore,"",trustStore);

                 //---------some code--------------------------------------

            return sf;
        } catch (Exception e) {
            throw new AssertionError(e);
        }
    }
} 

I found some similar articles but they didn't solve my problem. Maybe somebody faced with such problem. Thanks in advance......

YuDroid
  • 1,599
  • 5
  • 22
  • 44
drifter
  • 683
  • 1
  • 11
  • 24
  • What do you mean by don't work. What error do you get. – Mojo Risin May 30 '11 at 15:32
  • I have same problem like here: http://stackoverflow.com/questions/2899079/custom-ssl-handling-stopped-working-on-android-2-2-froyo But the solution from here didn't help me. Thanks in advance. – drifter Jun 01 '11 at 16:55

1 Answers1

0

Such configuration works for me (test it without adding 80 port):

SchemeRegistry   registry         = new SchemeRegistry();
SSLSocketFactory sslSocketFactory = SSLSocketFactory.getSocketFactory();
sslSocketFactory.setHostnameVerifier(SSLSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER);
registry.register(new Scheme("https", sslSocketFactory, 443));
SingleClientConnManager manager = new SingleClientConnManager(params, registry);
pawelzieba
  • 16,082
  • 3
  • 46
  • 72
  • Thanks for answer. I will test such approach in a few next days and will let to know about results. At this moment I postponed this problem. – drifter Jun 01 '11 at 16:52