在SpringBoot应用程序中PKIX路径构建失败,但在Main中却没有

时间:2019-07-09 06:03:47

标签: java spring-boot https certificate httpclient

我正在研究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);

为此指导我。

0 个答案:

没有答案