访问https双向认证两种方式
public static void httpsRequest(Context c) {
try {
String path = "https://localhost:8443/123.html";
BasicHttpParams params = new BasicHttpParams();
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
HttpProtocolParams.setContentCharset(params,
HTTP.DEFAULT_CONTENT_CHARSET);
HttpProtocolParams.setUseExpectContinue(params, true);
SSLSocketFactory.getSocketFactory().setHostnameVerifier(
new AllowAllHostnameVerifier());
SchemeRegistry schReg = new SchemeRegistry();
schReg.register(new Scheme("http", PlainSocketFactory
.getSocketFactory(), 80));
// 出错:因为使用了不被系统承认的自定义证书:No peer certificate 。
// schReg.register(new Scheme("https",SSLSocketFactory.getSocketFactory(), 443));
schReg.register(new Scheme("https", SSLTrustAllSocketFactory
.getSocketFactory(c), 443));
ClientConnectionManager connMgr = new ThreadSafeClientConnManager(
params, schReg);
DefaultHttpClient client = new DefaultHttpClient(connMgr, params);
HttpGet request = new HttpGet(path);
HttpResponse httpResponse = client.execute(request);
int responseCode = httpResponse.getStatusLine().getStatusCode();
String message = httpResponse.getStatusLine().getReasonPhrase();
HttpEntity entity = httpResponse.getEntity();
if (responseCode == 200 && entity != null) {
Log.e