我正在研究springboot应用程序,并且遇到了这个问题,
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
但是我的问题是,当我在单独的 main 方法上清洗以下代码段时,它可以完美运行并提供结果,但是当相同的代码在springboot应用程序下的服务功能中时,它将给出上述错误。帮助我理解和解决。
String url = "https://remote-service?user=testuser";
CloseableHttpClient client = HttpClients.createDefault();
HttpGet request = new HttpGet(url);
String encoding = DatatypeConverter.printBase64Binary("username:password".getBytes(StandardCharsets.UTF_8));
request.setHeader("Authorization", "Basic " + encoding);
// add request header
request.addHeader("User-Agent", USER_AGENT);
HttpResponse response = client.execute(request);
为此指导我。