欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 科技 > IT业 > httpClient发送https请求报错认证失败确少SSL证书的问题

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

2024/10/24 5:23:05 来源:https://blog.csdn.net/qq_42797527/article/details/140347889  浏览:    关键词: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);

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com