POST请求https遇到unable to find valid certification path to requested target

Maven 私服 unable to find valid certification path to requested target 错误 unable to find valid certification path to requested target 阅读详情

完整异常信息为:

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

问题出现原因是安全证书不信任。

我选择的方法是,发送请求的时候对带https的请求都选择信任

使用okhttp发送post请求pom如下:

<dependency>
    <groupId>com.squareup.okhttp3</groupId>
    <artifactId>okhttp</artifactId>
    <version>3.6.0</version>
</dependency>

代码如下:

public static JSONObject post(String url, HashMap<String, String> paramsMap) {
    Map<String, String> map = new HashMap<>();
    //设置对所有https证书信任
    TrustAllManager trustAllManager = new TrustAllManager();
    OkHttpClient.Builder okHttpClientaBuilder = new OkHttpClient.Builder().sslSocketFactory(createTrustAllSSLFactory(trustAllManager), trustAllManager);

    //获得client
    OkHttpClient okHttpClient = okHttpClientaBuilder.build();

    FormBody.Builder formBodyBuilder = new FormBody.Builder();
    Set<String> keySet = paramsMap.keySet();
    for (String key : keySet) {
        String value = paramsMap.get(key);
        formBodyBuilder.add(key, value);
    }
    FormBody formBody = formBodyBuilder.build();
    Request request = new Request
            .Builder()
            .post(formBody)
            .url(url)
            .build();
    JSONObject jason = null;
    try {
        Response response = okHttpClient.newCall(request).execute();


        if (response.code() == 201) {
            map.put("message", "success");
            map.put("status_code", "201");
            jason = JSONObject.parseObject(JSONObject.toJSON(map).toString());
        } else {
            jason = JSONObject.parseObject(response.body().string());
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return jason;
}

 

protected static SSLSocketFactory createTrustAllSSLFactory(TrustAllManager trustAllManager) {
    SSLSocketFactory ssfFactory = null;
    try {
        SSLContext sc = SSLContext.getInstance("TLS");
        sc.init(null, new TrustManager[]{trustAllManager}, new SecureRandom());
        ssfFactory = sc.getSocketFactory();
    } catch (Exception ignored) {
        ignored.printStackTrace();
    }

    return ssfFactory;
}
package com.otcbi.util.regwidutils;

import javax.net.ssl.X509TrustManager;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;

public class TrustAllManager implements X509TrustManager {
    @Override
    public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
    }

    @Override
    public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
    }

    @Override
    public X509Certificate[] getAcceptedIssuers() {
        return new X509Certificate[0];
    }
}

 

出现 PKIX path building failed unable to find valid certification path to requested target 解决方法 当出现"PKIX path building failed"错误时,说明JVM信任库中缺少对应的根证书或中间证书。文章提供了三种解决方案:1)测试环境下可忽略证书验证(不推荐生产环境);2)改用HTTP协议(如服务允许);3)生产环境应正确导入证书到JVM的cacerts。重点给出了一个忽略SSL验证的工具类SslUtils,通过调用ignoreSsl()方法可临时绕过证书验证,但强调该方法仅适用于本地测试,生产环境需采用标准证书 阅读详情

相关推荐

UniApp实现多端支付功能完整实现指南

支付业务流程多端支付实现安全性保障异常处理最佳实践支付基础知识多端支付实现统一支付封装安全性处理异常处理最佳实践根据具体业务场景选择合适的支付方式注重安全性和用户体验做好异常处理和日志记录持续优化和改进支付流程关注我,持续分享前端项目开发经验!

weixin_63454527的博客 2140

解决:unable to find valid certification path to requested target

问题 sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target 出现原因 这个问题的根本原因是你安装JDK时,Java\jar 1.8.0_141\lib\ext\里面缺少了一个安全凭证js

weixin_44519124的博客 6万+

TCP Reno/CUBIC 拥塞控制算法对比:从 Tahoe 到 BBR 的 4 种核心策略演进

本文深入解析了TCP拥塞控制算法的演进历程,从经典的Tahoe、Reno到现代的CUBIC和BBR,详细对比了4种核心策略的实现机制与性能差异。通过分析拥塞窗口、流量控制等关键技术,揭示了不同算法在高带宽延迟网络中的优化方向,为网络协议栈优化提供理论依据和实践指导。

weixin_33725239的博客 452

https请求报错unable to find valid certification path to requested target解决

在Java项目中请求HTTPS时,可能会遇到 "unable to find valid certification path to requested target" 错误。这个错误通常是由于SSL证书问题引起的。要解决此问题,可以尝试以下方法。

m0_38051458的博客 5万+

Temporal Fusion Transformer(TFT)与扩散模型融合:时间序列预测新范式

本文探讨了Temporal Fusion Transformer(TFT)与扩散模型融合的时间序列预测新范式。该融合方案利用TFT强大的特征提取与可解释性,为扩散模型提供精准的“导航图”,从而在噪声数据中实现鲁棒预测,并原生支持不确定性量化,输出完整的概率分布与置信区间,为金融、能源等领域的风险决策提供更可靠的依据。

weixin_29096377的博客 297

【大模型学习】第二十四章 生成式人工智能(GAI)简介

‌的AI技术,其核心目标是通过学习数据中的规律,生成与训练数据类似但全新的文本、图像、音频、视频甚至代码。生成式人工智能(GAI)是一类能够‌。

以实战经验介绍行业知识 1647

unable to find valid certification path to requested target

这个错误通常表示您的计算机或服务器无法验证 SSL 证书的有效性。可能是因为您正在尝试访问的网站使用的 SSL 证书过期了,或者证书的颁发机构不被您的计算机或服务器信任。 要解决这个问题,您可以尝试以下几个步骤: 检查您的系统日期和时间是否正确,因为 SSL 证书的有效期是有限的,如果您的计算机时间不正确,可能会导致 SSL 证书验证失败。 确认您的计算机或服务器信任证书的颁发机构。您可以手动...

weixin_42612405的博客 2万+

Graphviz安装及使用:决策树可视化

Python大数据分析与机器学习学习笔记 Graphviz安装及使用:决策树可视化

算法工程师 1万+

HttpClient请求https接口出现‘unable to find valid certification path to requested target’异常

背景 今天通过HttpClient请求一个外部接口时,出现SSLHandshakeException异常,通过查询并解决了问题,现做记录 以HTTP POST方式调用外部接口 public class HttpClientUtil { public static JSONObject httpPost(String url, String strParam,String appid, ...

小海子的博客 1万+

NVIDIA Jetson之交叉编译工具

参考:http://bbs.xfyun.cn/forum.php?mod=viewthread&amp;tid=33630 用TX2做红外热成像仪的识别,厂家不提供源码,只能提供对应版本的SDK,但是需要我们自己提供交叉编译器 由于之前没有做过交叉编译相关工作,对编译工具不太了解,因此查找相关资料学习下 交叉编译知识 一般来说,针对嵌入式平台的开发有两种编译模式:原生编译和交叉编译。原生编...

ZONGXP的博客 8392

Fakra连接器封装的PCB处理方式分析与总结

以往的项目中,关于Fakra连接器封装焊盘的PCB处理方式一直未有明确的规则定义,不同的处理方式,产生的效果各不相同,严重影响到设计的一致性,为此,本文针对这一设计上的缺陷进行了量化分析: 以十层板设计为例,分别从插入损耗(IL)、回波损耗(RL)、特性阻抗(Z0)三个维度进行了分析对比,最终,总结出适合的PCB设计规则,并且,该规则也适用于十层以外的叠构设计。

一只豌豆象的博客 2250

resttemplate 调用https 出错 unable to find valid certification path to requested target

resttemplate 调用https使用下面代码: @Bean @Primary public RestTemplate restTemplate(ClientHttpRequestFactory httpRequestFactory) { return new RestTemplate(httpRequestFactory); } @Be...

yueguanyun的专栏 9422

12、多端神经形态晶体管:原理、应用与算法探索

本文综述了多端神经形态晶体管的原理、应用与算法探索。从神经元MOS晶体管的发展到基于电解质栅极晶体管(EGT)的新型器件设计,系统阐述了其在低电压、多功能逻辑运算和突触行为模拟方面的优势。重点介绍了其在化学生物传感器(如多巴胺和pH检测)中的高灵敏度应用,以及在树突整合、时空总和、动态逻辑和神经元算术等树突算法中的实现。文章还总结了该类器件在神经形态计算、智能传感等领域的广阔前景,并分析了当前面临的材料工艺、理论建模与系统集成挑战,展望了未来发展方向。

delta的博客 148

解决unable to find valid certification path to requested target...的问题

今天在像服务器发送http请求的时候出现了unable to find valid certification path to requested target的错误,百度了下需要证书啥的。解决方式是在发送http请求的时候,可以过滤掉所有的https证书验证。 代码如下: /** * POST请求 * * @param url * @param data * @return...

never_mm的博客 5403

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

全球国家地区城市数据

MySQL全球国家地区城市数据报。。。。。。。。。。。。

java用HttpURLConnection发起HTTPS请求并跳过SSL证书,解决:unable to find valid certification path to requested targ

HttpUrlConnection请求忽略SSL认证请求

P_L_Wen97的博客 5363

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

https请求报错解决: unable to find valid certification path to requested target

最近使用https请求获取数据出现以下错误: 2017-10-12 16:58:10.113 [main] ERROR com.research.contactsrepairing.util.HttpUtil - post请求提交失败:https://10.100.32.150/kg/ir/repair/getRepaired/ javax.net.ssl.SSLHandshakeExcept

qq_15783243的博客 4375

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

Post: unable to find valid certification path to requested target

http发送post请求。 解决bug; https请求需要跳过验证。 package com.evisible.blockchain.common.utils; import javax.net.ssl.*; import java.security.cert.CertificateException; import java.security.cert.X509Certificate; public class SslUtils { private static void trustAl

weixin_39981289的博客 374

访问https无有效证书:unable to find valid certification path to requested target 问题解答

1.restTemplate或者httpClient没有特殊配置访问https接口的话会报这个错 Exception in thread "main" org.springframework.web.client.ResourceAccessException: I/O error on POST request for "https://XXXXX": sun.security.validato...

qq_24664619的博客 3030

https无法识别证书(unable to find valid certification path to requested target)的另类解法

项目中需要请求外部https的接口,由于项目的特殊性,采用比较通用的RestTemplate进行调用,在本地开发环境调试通过的,部署到服务器上却提示证书无法识别,具体报错信息如下(已屏蔽掉无关堆栈): org.springframework.web.client.ResourceAccessException: I/O error on POST request for "https://xxx.xxx.com/xxx/api/xxx": sun.security.validator.ValidatorEx

forgetmetoo的博客 4444

【unable to find valid certification path to requested target】问题处理

https请求报错unable to find valid certification path to requested target解决

山巅 1624

解决unable to find valid certification path to requested target

最近java程序去调用远程服务器接口时报错了:远程的接口地址用的是https,SSL证书也是我刚申请的,新的。

老徐的博客只有干货 3535

报错 unable to find valid certification path to requested target executing

这个问题的根本原因是你安装JDK时,Java\jar 1.8.0_141\lib\ext\里面缺少了一个安全凭证jssecacerts证书文件,通过运行下面类可以生成证书,将生成的证书放在Java\jar 1.8.0_141\lib\ext\这个目录下,重启编译器就可以解决。\src\main\java\com\ideal\sk>java InstallCert 需要访问的地址:端口。第一种:解决方式是在发送http请求的时候,可以过滤掉所有的https证书验证。执行完后会出现这样的界面。

weixin_39209728的博客 6886

JAVA http请求报错:unable to find valid certification path to requested target

JAVA http请求报错:unable to find valid certification path to requested target

mrye的博客 116

PKIX path building failed,SunCertPathBuilderException: unable to find valid certification path to re...

背景:有一个项目,需要调用gitlab的api,开发阶段在windows上进行。开发完成部署到linux中时,当请求gitlab接口的时候报如下错误: 2023.03.22 10:30:39.522 ERROR [http-nio-8089-exec-2] org.apache.juli.logging.DirectJDKLog 181 log - Servlet.service() for ...

zhenjingcool的博客 320

解决PKIX(PKIX path building failed) 问题 unable to find valid certification path to requested target...

最近在写java的一个服务,需要给远程服务器发送post请求,认证方式为Basic Authentication,在请求过程中出现了 PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to r...

weixin_30677617的博客 569
上一篇: 线程学习4:join方法的使用
下一篇: spring cloud 二刷总结摘抄记录
JavaMrSun
博客等级 码龄9年 27粉丝 64原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址