Android:javax.net.ssl.SSLException: hostname in certificate didn't match

问题:http请求的时候抛出 SSLException 错误
原因: 网站使用https服务器,请求的时候遇到证书验证错误。
解决:添加 SSLSocketFactory.getSocketFactory().setHostnameVerifier(new AllowAllHostnameVerifier());
或者

    try {
          httpResponse = new DefaultHttpClient().execute(httpPost);
     }catch (SSLException e){
           SSLSocketFactory.getSocketFactory().setHostnameVerifier(new AllowAllHostnameVerifier());
           httpResponse = new DefaultHttpClient().execute(httpPost);
     }

你可能感兴趣的:(踩过的坑)