DefaultHttpClient, Certificates, Https and posting problem!

后端 未结 1 1709
北恋
北恋 2021-02-06 19:08

My application needs to be able to post to https and preserve the session that is created with cookies. So far, i have several different ways of trying the problem and none are

1条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-06 19:43

    This issue is due to the fact that the client application is not able to validate build a certificate path from a trust anchor (a root trusted certification authority) and the SSL server certificate. Therefore this certificate is not trusted and the SSL handshake fails.

    The apache HTTPClient API provides a nice feature which could help you. The SSLSocketFactory constructor can take a KeyStore parameter, contains the trusted certificates.

    Then you can:

    1. create a KeyStore with keytool containing either the root CA certificate or the server certificate directly.
    2. add this keystore to your application
    3. builds the SSLSocketFactory with this KeyStore

    For all technical details and code snippets you can read this blog post from Bob Lee: http://blog.crazybob.org/2010/02/android-trusting-ssl-certificates.html

    0 讨论(0)
提交回复
热议问题