报错PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target"
今天在调用第三方HTTPS接口的时候,一直显示这个报错,然后百度很久,有2种解决方法,一个是说自己手动去导入,第二种用代码忽略证书验证。我用二种方式,
复制即用,
public void test2() throws Exception {
Map<String,Object> map=new LinkedHashMap<>();
map.put("teletephone",手机号码);
map.put("msgCode",车牌号);
map.put("msgContent",地址);
List<Map<String,Object>> list=new ArrayList<>();
list.add(map);
String params= JSONArray.toJSONString(list);
System.out.println(params);
BASE64Encoder encoder = new BASE64Encoder();
String encode = encoder.encode(params.getBytes());//编码
System.out.println(encode);
URL console = new URL("第三方路径?method=sendMSGPublic&id=1¶ms="+params);
HttpURLConnection conn = (HttpURLConnection) console.openConnection();
if (conn instanceof HttpsURLConnection) {
SSLContext sc = SSLContext.getInstance("SSL");
sc.init(null, new TrustManager[]{new TrustAnyTrustManager()}, new java.security.SecureRandom());
((HttpsURLConnection) conn).setSSLSocketFactory(sc.getSocketFactory());
((HttpsURLConnection) conn).setHostnameVerifier(new TrustAnyHostnameVerifier());
}
conn.connect();
System.out.println(conn.getResponseCode());
if(200 == conn.getResponseCode()){
//得到输入流
InputStream is =conn.getInputStream();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int len = 0;
while(-1 != (len = is.read(buffer))){
baos.write(buffer,0,len);
baos.flush();
}
System.out.println(baos.toString("utf-8"));
}
}
private static class TrustAnyTrustManager implements X509TrustManager {
public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
}
public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
}
public X509Certificate[] getAcceptedIssuers() {
return new X509Certificate[]{};
}
}
private static class TrustAnyHostnameVerifier implements HostnameVerifier {
public boolean verify(String hostname, SSLSession session) {
return true;
}
}
报错PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target"的更多相关文章
- 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 ...
- 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 ...
- 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 ...
- 解决 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 ...
- 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: ...
- 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 ...
- sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
httpclient-4.5.jar 定时发送http包,忽然有一天报错,http证书变更引起的. 之前的代码 try { CloseableHttpClient httpClient = build ...
- maven PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path
maven编译的时候遇到的奇葩问题, 非常奇葩, 所有其他同事都没有遇到 , 仅仅是我遇到了 不清楚是因为用了最新的JDK的缘故(1.8 update91)还是其他什么原因. 总之是证书的问题. 当 ...
- 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// ...
随机推荐
- 国密SM9算法C++实现(Linux)
首先参考 Linux下编译并使用miracl密码库 该博文在linux下编译Miracl库. 编译完了,自然是要用的,下面介绍两种在C程序中使用miracl库的方法. 方法一: 1. 源码编译完后的必 ...
- TensorFlow:使用inception-v3实现各种图像识别
程序来自博客: # https://www.cnblogs.com/felixwang2/p/9190740.html上面这个博客是一些列的,所以可以从前往后逐一练习. # https://www.c ...
- 11: Django + gunicorn + Nginx 的生产环境部署
1.1 gunicorn介绍 1.Gunicorn 1. Gunicorn是使用Python实现的WSGI服务器, 直接提供了http服务, 并且在woker上提供了多种选择, gevent, e ...
- Laravel Vuejs 实战:开发知乎 (8)美化编辑器
1.使用UEditor增量包: simple-ueditors 执行下载: git clone https://github.com/JellyBool/simple-ueditor.git 2.用此 ...
- min-25筛总结
怕忘了赶快更一下.就是求积性函数前缀和的. 没有 \(\LaTeX\) 原理 现在你有一个积性函数 f(1)=1 FP(p) FPK(p,k) 首先要求的是前缀和,那就是f(质数)+f(合数)+f(1 ...
- JS-apply、call、bind
最近查看了很多关于apply的文章,就随手记录一下. Apply apply: 方法能劫持另外一个对象的方法,继承另外一个对象的属性. Function.apply(obj,args) 方法能接收两个 ...
- workspace 打开的是我的电脑
在system tree板块的空白处右键-->set root-->current workspace 即可恢复workspace.
- JavaScirpt - 模块的写法
传送门 http://www.ruanyifeng.com/blog/2012/10/javascript_module.html 1. 原始写法 function f1() { // do sth. ...
- redis的使用1
学Linux已经将近一个月了,Linux中讲到的redis的使用,到现在还不回具体的使用在php中,今天周末,于是想把redis的使用搞懂. 网上的资料不算多,但还需要硬着头皮学.其中找到这样一篇关于 ...
- 一类Log-Gamma积分的一般形式
\[\Large\int_{0}^{z}x^{t}\ln\Gamma \left ( 1+x \right )\mathrm{d}x~,~z>0\, ,\, t\in N^{*}\] \(\La ...