httpClient发送https请求报错认证失败确少SSL证书的问题

报错内容

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

解决办法
1NG做跳转处理,先将https请求改为向ng发送http请求,ng做跳板发送https请求

server {
          listen       80;
          server_name _;
          return 301 https://$host$request_uri;
}

解决办法2
服务端配置跳过ssl认证

 HttpPost post = new HttpPost(url);
        //创建CloseableHttpClient对象-忽略SSL证书
        CloseableHttpClient client = null;
        try {
            SSLConnectionSocketFactory scsf = new SSLConnectionSocketFactory(
                    SSLContexts.custom().loadTrustMaterial(null, new TrustSelfSignedStrategy()).build(),
                    NoopHostnameVerifier.INSTANCE);
            client = HttpClients.custom().setSSLSocketFactory(scsf).build();
        } catch (KeyManagementException e) {
            logger.error("调用接口失败:",e);
        } catch (NoSuchAlgorithmException e) {
            logger.error("调用接口失败:",e);
        } catch (KeyStoreException e) {
            logger.error("调用接口失败:",e);
        }
        RequestConfig requestConfig = RequestConfig.custom()
                .setConnectTimeout(connectTimeout)
                .setSocketTimeout(socketTimeout)
                .build();
        post.setConfig(requestConfig);
        ByteArrayEntity entity = new ByteArrayEntity(data.getBytes(StandardCharsets.UTF_8));
        entity.setContentType("application/json");
        post.setEntity(entity);
        CloseableHttpResponse res = client.execute(post);

相关推荐

  1. httpclient访问https请求处理

    2024-07-12 12:56:05       19 阅读
  2. https地址发送请求失败

    2024-07-12 12:56:05       19 阅读
  3. okHttphttps请求忽略ssl证书认证

    2024-07-12 12:56:05       23 阅读
  4. Okhttp 发送https请求,忽略ssl认证

    2024-07-12 12:56:05       28 阅读
  5. SSL通信、证书认证原理和失败原因

    2024-07-12 12:56:05       32 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-12 12:56:05       67 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-12 12:56:05       71 阅读
  3. 在Django里面运行非项目文件

    2024-07-12 12:56:05       58 阅读
  4. Python语言-面向对象

    2024-07-12 12:56:05       69 阅读

热门阅读

  1. Vim 编辑文件时中文乱码的解决方法

    2024-07-12 12:56:05       18 阅读
  2. vim删除多行

    2024-07-12 12:56:05       24 阅读
  3. 嵌入式裸机开发与 Linux 开发

    2024-07-12 12:56:05       21 阅读
  4. 机器学习-分类器-总结

    2024-07-12 12:56:05       18 阅读
  5. Git-如何基于某个tag创建一个新分支

    2024-07-12 12:56:05       27 阅读
  6. 【Linux】Vim 使用教程

    2024-07-12 12:56:05       16 阅读
  7. Hive中的数据类型和存储格式总结

    2024-07-12 12:56:05       21 阅读
  8. modern C++:闭包与匿名函数

    2024-07-12 12:56:05       23 阅读
  9. 前缀,中缀,后缀表达式

    2024-07-12 12:56:05       22 阅读
  10. 笔记:如何使用Microsoft.Extensions.Options

    2024-07-12 12:56:05       30 阅读
  11. socket编程(1)

    2024-07-12 12:56:05       30 阅读
  12. stm32flash一键ISP烧录单片机

    2024-07-12 12:56:05       20 阅读