• 调用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);
    }
    }
  • 相关阅读:
    window.open() 使用详解
    20151117
    20151116
    打开一个网页并弹窗提示,点击确定后2秒后关闭
    网页制作中的一点问题及解决方案
    Android WebView 开发详解(二)
    Android WebView 开发详解(一)
    Android:控件WebView显示网页
    Dagger 2: Step To Step
    Introducing RecyclerView(二)
  • 原文地址:https://www.cnblogs.com/wangchaoyu/p/11585164.html
Copyright © 2020-2023  润新知