Java Unirest 禁用证书

mun*_*yso 3 java spring unirest spring-boot

您能否告诉我如何禁用使用 Unirest 作为休息客户端的证书验证。

我将 Unirest 与 Java Spring 结合使用。下面是我的源代码:

try {
    HttpResponse<String> response = Unirest.post("myurl")
      .header("content-type", "application/json")
      .header("accept", "application/json")
      .body("my json data here")
      .asJson();
} catch (Exception e) {
    logger.info("==================REST CLIENT ERROR: "+e.getMessage());
}
Run Code Online (Sandbox Code Playgroud)

结果:

==================REST客户端错误:javax.net.ssl.SSLHandshakeException:sun.security.validator.ValidatorException:PKIX路径构建失败:sun.security.provider.certpath .SunCertPathBuilderException:无法找到请求目标的有效证书路径

小智 5

我知道这个线程很旧,但只是写以防其他人正在寻找更简单的方法。

Unirest 现在对此有内置支持。

Unirest.config().verifySsl(false);

这对我有用。