HttpClient4.x send request over SSL
HttpClient4.x send request over SSL
蜡笔小小小新 发表于1年前
HttpClient4.x send request over SSL
  • 发表于 1年前
  • 阅读 13
  • 收藏 0
  • 点赞 0
  • 评论 0

腾讯云 技术升级10大核心产品年终让利>>>   

private CloseableHttpClient httpClient;
	private HttpContext httpContext;
	private HttpClientContext context;

 

public Login () {
		
		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,SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
            
            this.httpClient = HttpClients.custom().setSSLSocketFactory(sslsf).build() ;
			this.httpContext = new BasicHttpContext();
			this.context = HttpClientContext.adapt(httpContext);
			
		} catch (Exception e) {
			log.error("Configuration SSL error",e.getMessage());
		}
	}

 

标签: HTTP
共有 人打赏支持
粉丝 29
博文 112
码字总数 79661
×
蜡笔小小小新
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
* 金额(元)
¥1 ¥5 ¥10 ¥20 其他金额
打赏人
留言
* 支付类型
微信扫码支付
打赏金额:
已支付成功
打赏金额: