httpclient 4.3 ignore certificate_JAVA_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > JAVA > httpclient 4.3 ignore certificate

httpclient 4.3 ignore certificate

 2014/4/22 12:32:40  id.alex  程序员俱乐部  我要评论(0)
  • 摘要:publicstaticCloseableHttpClientcreateSSLInsecureClient()throwsGeneralSecurityException{try{SSLContextsslContext=newSSLContextBuilder().loadTrustMaterial(null,newTrustStrategy(){publicbooleanisTrusted(X509Certificate[]chain,StringauthType
  • 标签:client Certificate HTTP
class="java" name="code">

	public static CloseableHttpClient createSSLInsecureClient() throws GeneralSecurityException {
		try {
			SSLContext sslContext = new SSLContextBuilder().loadTrustMaterial(null, new TrustStrategy() {
				public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException {
					return true;
				}
			}).build();
			SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext, new X509HostnameVerifier() {

				@Override
				public boolean verify(String arg0, SSLSession arg1) {
					return true;
				}

				@Override
				public void verify(String host, SSLSocket ssl) throws IOException {
				}

				@Override
				public void verify(String host, X509Certificate cert) throws SSLException {
				}

				@Override
				public void verify(String host, String[] cns, String[] subjectAlts) throws SSLException {
				}

			});
			return HttpClients.custom().setSSLSocketFactory(sslsf).build();
		} catch (GeneralSecurityException e) {
			throw e;
		}
	}

发表评论
用户名: 匿名