End https presence bypass certificate validation code logic
{the try
// bypass the authentication process by way of https requests
the SSLContext SSLContext = createIgnoreVerifySSL ();
// 设置协议http和https对应的处理socket链接工厂的对象
Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder
.<ConnectionSocketFactory> create()
.register("http", PlainConnectionSocketFactory.INSTANCE)
.register(
"https",
new SSLConnectionSocketFactory(sslcontext,
new AllowAllHostnameVerifier())).build();
PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager(
socketFactoryRegistry);
HttpClients.custom().setConnectionManager(connManager);
// Create custom httpclient objects
CloseableHttpClient Client = HttpClients.custom ()
.setConnectionManager (connManager) .build ();
// Create the request object get embodiment
HttpGet HttpGet = new new HttpGet ( URL );
// perform the requested operation, and to get the result (synchronous blocking)
CloseableHttpResponse client.execute Response = (HttpGet);
. Int = response.getStatusLine statusCode () getStatusCode ();
IF (== 200 is statusCode) {// return the correct
// Get entities that
the HttpEntity = response.getEntity entity ();
IF (! entity = null) {
// the specified transcoder entity is the result of type String
rdata = EntityUtils.toString (entity, "UTF-. 8");
}
EntityUtils.consume (entity); // close all streams entity
}
// release link
response.close();
} catch (Exception e) {
}
public static SSLContext createIgnoreVerifySSL()
throws NoSuchAlgorithmException, KeyManagementException {
SSLContext sc = SSLContext.getInstance("SSLv3");
// implement a X509TrustManager interface for bypassing verification without modification which method
X509TrustManager TrustManager new new X509TrustManager = () {
@Override
public void CheckClientTrusted (
of java.security.cert.X509Certificate [] paramArrayOfX509Certificate,
String o paramString) throws a CertificateException {
}
@Override
public void checkServerTrusted(
java.security.cert.X509Certificate[] paramArrayOfX509Certificate,
String paramString) throws CertificateException {
}
@Override
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return null;
}
};
sc.init(null, new TrustManager[] { trustManager }, null);
return sc;
}