• 调用https接口 报错:unable to find valid certification path


    网上查了一大堆 基本都是 keytool导入证书

    keytool -import -alias ee  -keystore "C:Program FilesJavajre1.8.0_221libsecuritycacerts" -file D:certee.cer -storepass changeit

    但是:导入完之后我遇到了一个问题 莫名其妙的有时候好使有时候不好使

    最终尝试了N+1次之后,发现 证书名字和别名是一个字母也提示添加成功 但是就是不好使,2个字母就好使(我也不知道什么原因)

    RestTemplate POST 请求证书验证解决办法

    final static RestTemplate restTemplate = new RestTemplate(generateHttpsRequestFactory());
    private static HttpComponentsClientHttpRequestFactory generateHttpsRequestFactory() {
    try {
    TrustStrategy acceptingTrustStrategy = (x509Certificates, authType) -> true;
    SSLContext sslContext = SSLContexts.custom().loadTrustMaterial(null, acceptingTrustStrategy)
    .build();
    SSLConnectionSocketFactory connectionSocketFactory =
    new SSLConnectionSocketFactory(sslContext, new NoopHostnameVerifier());

    HttpClientBuilder httpClientBuilder = HttpClients.custom();
    httpClientBuilder.setSSLSocketFactory(connectionSocketFactory);
    CloseableHttpClient httpClient = httpClientBuilder.build();
    HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory();
    factory.setHttpClient(httpClient);
    factory.setConnectTimeout(5 * 1000);
    factory.setReadTimeout(5 * 1000);
    return factory;
    } catch (Exception e) {
    throw new RuntimeException("创建HttpsRestTemplate失败", e);
    }
    }
  • 相关阅读:
    配置caffe matlab 中遇到的坑
    VGGnet论文总结(VERY DEEP CONVOLUTIONAL NETWORKS FOR LARGE-SCALE IMAGE RECOGNITION)
    内核笔记
    VM上安装centos6.x & java & tomcat & mysql
    ----
    python 入门笔记
    centos7 安装 mysql & jetty
    VM 中 CentOS 6 的相关配置
    论文 单词句子笔记
    Android 百度地图开发(三)--- 实现比例尺功能和替换自带的缩放组件
  • 原文地址:https://www.cnblogs.com/wangchaoyu/p/11585164.html
Copyright © 2020-2023  润新知