/**
* 屏蔽HTTPS 的SSL 证书验证。
* @param httpsconnection
* @throws NoSuchAlgorithmException
* @throws KeyManagementException
*/
private static void ignoreValidateCertification(
HttpsURLConnection httpsconnection)
throws NoSuchAlgorithmException, KeyManagementException
{
SSLContext ssl = SSLContext.getInstance("SSL");
X509TrustManager[] tm = new X509TrustManager[] { new X509TrustManager() {
public X509Certificate[] getAcceptedIssuers()
{
return null;
}
public void checkClientTrusted(X509Certificate[] arg0, String arg)
{
}
public void checkServerTrusted(X509Certificate[] arg0, String arg)
{
}
} };
httpsconnection.setHostnameVerifier(new HostnameVerifier() {
public boolean verify(String host, SSLSession session)
{
return true;
}
});
httpsconnection.setSSLSocketFactory(ssl.getSocketFactory());
}
* 屏蔽HTTPS 的SSL 证书验证。
* @param httpsconnection
* @throws NoSuchAlgorithmException
* @throws KeyManagementException
*/
private static void ignoreValidateCertification(
HttpsURLConnection httpsconnection)
throws NoSuchAlgorithmException, KeyManagementException
{
SSLContext ssl = SSLContext.getInstance("SSL");
X509TrustManager[] tm = new X509TrustManager[] { new X509TrustManager() {
public X509Certificate[] getAcceptedIssuers()
{
return null;
}
public void checkClientTrusted(X509Certificate[] arg0, String arg)
{
}
public void checkServerTrusted(X509Certificate[] arg0, String arg)
{
}
} };
ssl.init(null, tm, new SecureRandom());
httpsconnection.setHostnameVerifier(new HostnameVerifier() {
public boolean verify(String host, SSLSession session)
{
return true;
}
});
httpsconnection.setSSLSocketFactory(ssl.getSocketFactory());
}