你可以寫一個TrustManager類來處理它。 例如:
ClientConnectionManager cm = new BasicClientConnectionManager();
cm.getSchemeRegistry().register(createHttpsScheme());
DefaultHttpClient client = new DefaultHttpClient(cm);
String url = "https://your domain/your url";
HttpGet get = new HttpGet(url);
HttpResponse resp = client.execute(get);
etc..
public static Scheme createHttpsScheme() {
SSLContext context = SSLContext.getInstance("TLS");
context.init(null, new TrustManager[] {
new TestTrustManager()
}, new SecureRandom());
SSLSocketFactory sf = new SSLSocketFactory(context);
return new Scheme("https", 443, sf);
}
INT TestTrustManager.java可以打印鏈是這樣的:
public class TestTrustManager implements X509TrustManager {
@Override
public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
for (int i = 0; i < chain.length; ++i) {
System.out.println(chain[i]);
}
decorated.checkServerTrusted(chain, authType);
}
}
我也想知道,但我找不到任何線索。 :S – gnclmorais 2011-02-03 18:51:46