1. 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. 2.8.2 并发下的ArrayList,以及源码分析

    package 第二章.并发下的ArrayList; import java.util.ArrayList;import java.util.List; /** * Created by zzq on ...

  2. Session.Abandon-Session.Clear-Session.RemoveAll

    System.Web.UI.Page.Session属性和System.Web.HttpContext.Session属性 都是System.Web.SessionState.HttpSessionS ...

  3. Debian7安装后的配置(英文环境chromium浏览器中汉字变成方块的问题)

    原文来自:http://www.programgo.com/article/3272573017/ 1.安装文泉宋体 sudo aptitude install xfonts-wqy sudo apt ...

  4. .net Reflection(反射)- 二

    反射 Reflection 中访问方法 新建一个ClassLibrary类库: public class Student { public string Name { get; set; } publ ...

  5. DataType--类型基础

    数据类型数据的定义在各种场合均不一样,数据的载体也不一样,数据的表现方式和传递方式也不一样,数据的处理方式也不一样,数据库不可能处理所有形式的数据,因此必须规范数据,按照类型划分和处理. 连续和离散( ...

  6. Ubuntu16.04修改静态ip地址

    https://blog.csdn.net/mdw5521/article/details/79270035

  7. VSCode调试C#控制台与单元测试

    公司前端最近项目里面在用VSCode编写前端代码,觉得这个编辑器很轻便,既然是微软出的,肯定支持C#,就去网上查了查资料,发现还真是支持C#,并且蛮多地方用到dotnet命令,哈哈. 1.powers ...

  8. Weekly Contest 118

    970. Powerful Integers Given two non-negative integers x and y, an integer is powerful if it is equa ...

  9. 加密模块(md5)

    一.md5加密 import hashlib s = ' print(s.encode()) m = hashlib.md5(s.encode())# 必须得传一个bytes类型的 print(m.h ...

  10. oracle为IN OUT变量或OUT变量赋值时提示“表达式''不能用作赋值目标”

    是因为IN OUT变量和OUT变量是要输出的,不能赋给它常量值,这样它就不能再被赋值而输出了,所以是禁止赋常量值的,比如''也是常量值,也不可以赋给这两种类型的变量,如果不能把存储过程中的其他变量赋给 ...