httpclient-4.5.jar 定时发送http包,忽然有一天报错,http证书变更引起的。

之前的代码

try {

            CloseableHttpClient httpClient = buildDefaultHttpClient();
String url = domain.getUrl();
HttpGet httpGet = new HttpGet(url);
httpGet.addHeader("User-Agent", NetUtil.INSPECTOR_USER_AGENT);
httpGet.addHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8");
httpGet.addHeader("Accept-Encoding", "gzip, deflate");
httpGet.addHeader("Accept-Language", "zh-CN,zh;q=0.9"); CloseableHttpResponse resp = httpClient.execute(httpGet); String responseBody = EntityUtils.toString(resp.getEntity(), "utf-8"); respEnd = DateUtil.toEpochMilliseconds(LocalDateTime.now()); len = responseBody.length(); logger.info("http报文响应正文长度:{}B", len); String extractedTitle = NetUtil.extractTitle(responseBody); return builder.withRespEnd(respEnd).withRespLen(len)
.withHttpStatus((short) resp.getStatusLine().getStatusCode())
.withRetrieveTitle(extractedTitle)
.withTitleMatched(StringUtils.equals(domain.getTitle(), extractedTitle))
.build(); } catch (IOException e) {
}

之后的代码

try {

            CloseableHttpClient httpClient = buildDefaultHttpClientTrustSSL();//信任证书

            String url = domain.getUrl();
HttpGet httpGet = new HttpGet(url);
httpGet.addHeader("User-Agent", NetUtil.INSPECTOR_USER_AGENT);
httpGet.addHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8");
httpGet.addHeader("Accept-Encoding", "gzip, deflate");
httpGet.addHeader("Accept-Language", "zh-CN,zh;q=0.9"); CloseableHttpResponse resp = httpClient.execute(httpGet); String responseBody = EntityUtils.toString(resp.getEntity(), "utf-8"); respEnd = DateUtil.toEpochMilliseconds(LocalDateTime.now()); len = responseBody.length(); logger.info("http报文响应正文长度:{}B", len); String extractedTitle = NetUtil.extractTitle(responseBody); return builder.withRespEnd(respEnd).withRespLen(len)
.withHttpStatus((short) resp.getStatusLine().getStatusCode())
.withRetrieveTitle(extractedTitle)
.withTitleMatched(StringUtils.equals(domain.getTitle(), extractedTitle))
.build(); } catch (IOException e) {
}
 /**
* 信任SSL证书
* @return
*/
public static CloseableHttpClient buildDefaultHttpClientTrustSSL()
{
SSLContext sslContext = null;
try {
sslContext = SSLContextBuilder.create().useProtocol(SSLConnectionSocketFactory.SSL).loadTrustMaterial((x, y) -> true).build();
} catch (Exception e) {
e.printStackTrace();
}
RequestConfig config = RequestConfig.custom()
.setSocketTimeout(30000)
.setConnectTimeout(30000)
.setConnectionRequestTimeout(30000)
.setContentCompressionEnabled(true)
.build();
return HttpClientBuilder.create().setDefaultRequestConfig(config).setSSLContext(sslContext).setSSLHostnameVerifier((x, y) -> true).build();
} public static CloseableHttpClient buildDefaultHttpClient()
{
RequestConfig defaultRequestConfig = RequestConfig.custom()
.setSocketTimeout(30000)
.setConnectTimeout(30000)
.setConnectionRequestTimeout(30000)
.setContentCompressionEnabled(true)
.setStaleConnectionCheckEnabled(true)
.build(); return HttpClients.custom().setDefaultRequestConfig(defaultRequestConfig).build();
}

sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target的更多相关文章

  1. Maven:sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

    还是记录使用 maven 时遇到的问题. 一.maven报错 maven package 进行打包时出现了以下报错: Non-resolvable parent POM for com.wpbxin: ...

  2. mvn 编译报错mavn sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested targ

    mavn 编译报错: mavn sun.security.validator.ValidatorException: PKIX path building failed: sun.security.p ...

  3. 解决 java 使用ssl过程中出现"PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target"

    今天,封装HttpClient使用ssl时报一下错误: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorExc ...

  4. java程序中访问https时,报 PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

    在java中使用https访问数据时报异常: Caused by: sun.security.validator.ValidatorException: PKIX path building fail ...

  5. PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

    注:网上搜来的快照,暂未验证 在java代码中请求https链接的时候,可能会报下面这个错误javax.net.ssl.SSLHandshakeException: sun.security.vali ...

  6. Flutter配置环境报错“PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target”

    背景:最近看了很多Flutter漂亮的项目,想要尝试一下.所有环境都搭建好之后,按照文档一步一步配置(抄袭),但始终报如下图错误. PKIX path building failed: sun.sec ...

  7. ES访问遇到sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

    cmd命令cd到jre/bin目录下 输入命令keytool -import -alias 别名 -keystore cacerts -file ‪C://certs//elasticsearch// ...

  8. maven PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path

    maven编译的时候遇到的奇葩问题,  非常奇葩, 所有其他同事都没有遇到 , 仅仅是我遇到了 不清楚是因为用了最新的JDK的缘故(1.8 update91)还是其他什么原因. 总之是证书的问题. 当 ...

  9. 报错PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target"

    今天在调用第三方HTTPS接口的时候,一直显示这个报错,然后百度很久,有2种解决方法,一个是说自己手动去导入,第二种用代码忽略证书验证.我用二种方式, 复制即用, public void test2( ...

随机推荐

  1. java-面试题为什么redis这么快

    文章:为什么说Redis是单线程的以及Redis为什么这么快! 文章比较详细,有些细节可能需要注意. 1,比如CPU不是redis的瓶颈 2,随着连接数的增加,并发会降低等.

  2. 【转载】softmax的log似然代价函数(求导过程)

    全文转载自:softmax的log似然代价函数(公式求导) 在人工神经网络(ANN)中,Softmax通常被用作输出层的激活函数.这不仅是因为它的效果好,而且因为它使得ANN的输出值更易于理解.同时, ...

  3. JavaScript柯里化(currying)

    参考: https://www.jianshu.com/p/33392cb4b055 https://ruby-china.org/topics/38385 https://stackoverflow ...

  4. 安装tensorflow遇到:Your CPU supports instructions that this TensorFlow binary was not compiled to use

    为了提升CPU计算速度的.若你有支持cuda的GPU,则可以忽略这个问题,因为安装SSE4.1, SSE4.2, AVX, AVX2, FMA, 仅仅提升CPU的运算速度(大概有3倍). 解决方法: ...

  5. return new Promise的时候,不能带着.then()方法

    app.js return new Promise的同时带着.then()方法会出错 return出去的这个Promise,整体状态会显示pending,虽然详细里状态显示resolve,但是没有re ...

  6. python操作hive 安装和测试

    方法一:使用pyhive库 如上图所示我们需要四个外部包 中间遇到很多报错.我都一一解决了 1.Connection Issue: thrift.transport.TTransport.TTrans ...

  7. php类知识点滴---类的实例化,构造函数,继承初步

    实例化类----黑科技用法,通过字符串来实例化 class coach { public function __construct() { echo "欢迎光临北武堂"." ...

  8. 浅析BFC及其作用

    本文链接:https://blog.csdn.net/riddle1981/article/details/52126522

  9. Practical, Dynamic Visibility for Games(可实现动态显示技术)

    Practical, Dynamic Visibility for Games(可实现动态显示技术) 原文地址 1引言 游戏场景越来越复杂,包含的内容越来越多,动态显示技术很需要. 本文介绍2种互补的 ...

  10. PHP中使用PDO的预处理功能避免SQL注入

    不使用预处理功能 <?php $id = $_GET['id']; $dsn = 'mysql:host=localhost;port=3306;dbname=database'; try { ...