HttpClientBuilder b = HttpClientBuilder.create();
// setup a Trust Strategy that allows all certificates.
//
SSLContext sslContext;
try {
sslContext = new SSLContextBuilder().loadTrustMaterial(null, (i, j) -> true).build();
} catch (Exception e) {
throw new RuntimeException(e);
}
b.setSslcontext(sslContext);
// don't check Hostnames, either.
// -- use SSLConnectionSocketFactory.getDefaultHostnameVerifier(), if you don't want to weaken
HostnameVerifier hostnameVerifier = NoopHostnameVerifier.INSTANCE;
// here's the special part:
// -- need to create an SSL Socket Factory, to use our weakened "trust strategy";
// -- and create a Registry, to register it.
//
SSLConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(sslContext, hostnameVerifier);
Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder.<ConnectionSocketFactory>create()
.register("http", PlainConnectionSocketFactory.getSocketFactory())
.register("https", sslSocketFactory)
.build();
// now, we create connection-manager using our Registry.
// -- allows multi-threaded use
PoolingHttpClientConnectionManager connMgr = new PoolingHttpClientConnectionManager(socketFactoryRegistry);
if(PropertiesUtils.getInstance().getSwitch("httpclient.control.switch")){
// 总连接数
connMgr.setMaxTotal(PropertiesUtils.getInstance().getProperty("httpclient.maxTotalConnections", 50));
// 同路由的并发数
connMgr.setDefaultMaxPerRoute(PropertiesUtils.getInstance().getProperty("httpclient.maxConnectionPerHost", 10));
b.setConnectionManager(connMgr);
// 失败默认重试3次
b.setRetryHandler(new DefaultHttpRequestRetryHandler());
}else{
connMgr.setMaxTotal(200);
connMgr.setDefaultMaxPerRoute(100);
b.setConnectionManager(connMgr);
// finally, build the HttpClient;
// -- done!
}
return b.build();

利用httpClient发起https请求的更多相关文章

  1. httpclient发起https请求以及获取https返回内容

    工作中的需要,使用Apache httpclient发起获取通过https返回的内容,试了很多网上的解决办法都不行,查阅了Apache httpclient的官方文档,最后终于找出解决方法,分享给需要 ...

  2. JAVA利用HttpClient进行POST请求(HTTPS)

    目前,要为另一个项目提供接口,接口是用HTTP URL实现的,最初的想法是另一个项目用jQuery post进行请求. 但是,很可能另一个项目是部署在别的机器上,那么就存在跨域问题,而JQuery的p ...

  3. 老李分享:curl发起https请求

    老李分享:curl发起https请求 在POPTEST上课的过程中,我们需要本地模拟https请求来完成性能测试,我们用curl来实现,curl是利用URL语法在命令行方式下工作的开源文件传输工具,使 ...

  4. java如何发起https请求

    1.写一个SSLClient类,继承至HttpClient import java.security.cert.CertificateException; import java.security.c ...

  5. java利用HttpClient进行https接口调用

    1.为了避免需要证书,所以用一个类继承DefaultHttpClient类,忽略校验过程. import java.security.cert.CertificateException; import ...

  6. C# 应用 - 使用 HttpClient 发起 Http 请求

    1. 需要的库类 \Reference Assemblies\Microsoft\Framework\.NETFramework\v4.7.2\System.Net.Http.dll System.N ...

  7. php 使用curl发起https请求

    今天一个同事反映,使用curl发起https请求的时候报错:“SSL certificate problem, verify that the CA cert is OK. Details: erro ...

  8. http 使用curl发起https请求报错的解决办法

    使用curl发起https请求的时候报错:“SSL certificate problem, verify that the CA cert is OK. Details: error:1409008 ...

  9. 用curl发起https请求

    使用curl发起https请求 使用curl如果想发起的https请求正常的话有2种做法: 方法一.设定为不验证证书和host. 在执行curl_exec()之前.设置option $ch = cur ...

随机推荐

  1. datagrid 自定义 pager

    $(document).ready(function(){ var p = $('.easyui-datagrid').datagrid('getPager'); $(p).pagination({ ...

  2. 【转】微信中MMAlert(半透明底部弹出菜单)的使用介绍

    原文地址:http://blog.csdn.net/singwhatiwanna/article/details/8892930 果大家时常用过微信或者用过iphone,就会发现有种从底部弹出的半透明 ...

  3. WCF分布式开发步步为赢(1):WCF分布式框架基础概念

    众所周知,系统间的低耦合一直是大型企业应用系统集成追寻的目标,SOA面向服务架构的出现为我们的如何利用现有企业系统资源进行企业ERP系统设计和实现提供了重要的参考原则.SOA如此炙手可热,各大厂商都推 ...

  4. 「BZOJ 3280」小R的烦恼

    题目链接 戳我 \(Solution\) 这道题很像餐巾计划啊. 首先将每天拆成\(x\)和\(x'\),\(S->x\)流量为\(a_i\),费用为\(0\)表示一天下来有\(a_i\)个濒死 ...

  5. Mysql的用户基本操作

    创建用户: mysql> create user 'cai'@'localhost' identified by '123456'; Query OK, 0 rows affected (0.0 ...

  6. python爬虫的一些小小问题、python动态正则表达式

    1.首先urllib不能用了,需要引入的是urllib2,正则re. #coding=utf-8 # import urllib import urllib2 import re def getHtm ...

  7. Jenkins持续集成企业实战系列之两种网站部署的流程-----01

    注:原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.    最初接触Jenkins也是由于公司需求,根据公司需求Java代码项目升级的.(公司是 ...

  8. 使用window.name 进行数据跨域传递

    其中要点, Stpe1,浏览器在Iframe中加载一个异域的页面,这个页面返回 <script>window.name="任何数据"</script>,这时 ...

  9. VUE学习(一)

    1.搭建vue环境 2.了解 v-on  事件监听,常常跟事件(click,mousemove,change等鼠标或者手势事件)在一起,eg:v-on:click,语法糖——:(冒号) 需要在meth ...

  10. [POI2007]ZAP-Queries 数学

    题目描述 Byteasar the Cryptographer works on breaking the code of BSA (Byteotian Security Agency). He ha ...