平台服务调用https接口报错: org.springframework.WEB.client.ResourceAccessException: I/0 error on PoST request for ?"Https://XXXX
平台服务调用https接口报错:
org.springframework.WEB.client.ResourceAccessException: I/0 error on PoST request for ?"Https://XXXXX": java.security.centp.CertificateException: No subject alternative names present; nested exception is javax.net.ssl..SSLHandshakeException: java.security.cert.CertificateException: No subject alternative namesspresent
第一种方法:配置相关SSL证书到服务器
第二种方法:如果没有相关服务器权限,又想快速验证接口调用,可以在请求时添加跳过SSL证书,可以 快捷实现,当然生产环境还是建议配置证书方式,降低风险
public static String sendAskSkipSSLCertificate(String url, Map body, Map header) throws Exception { CloseableHttpResponse response = null; // 处理请求路径 url = UriComponentsBuilder.fromHttpUrl(url) .toUriString(); //创建httpclient对象 CloseableHttpClient client = null; String respBody; client = HttpClients.custom().setSSLSocketFactory(new SSLConnectionSocketFactory(SSLContexts.custom() .loadTrustMaterial(null, new TrustSelfSignedStrategy()).build(), NoopHostnameVerifier.INSTANCE)).build(); //创建post方式请求对象 HttpPost httpPost = new HttpPost(url); // 请求头设置 httpPost.setHeader("Content-Type", "application/JSON"); if (header != null) { for (String s : header.keySet()) { httpPost.setHeader(s, header.get(s)); } } if (body != null) { httpPost.setEntity(new StringEntity(jsON.toJSONString(body), "utf-8")); } response = client.execute(httpPost); org.apache.http.HttpEntity entity = response.getEntity(); if (entity != null) { respBody = EntityUtils.toString(entity); return respBody; } return null; }
来源地址:https://blog.csdn.net/Zxiaobinggan/article/details/129306508
--结束END--
本文标题: 发送https请求并跳过ssl证书验证
本文链接: https://www.lsjlt.com/news/401569.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-04-03
2024-04-03
2024-04-01
2024-01-21
2024-01-21
2024-01-21
2024-01-21
2023-12-23
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0