为了账号安全,请及时绑定邮箱和手机立即绑定

将REST客户端与标头一起使用时获取ssl.SSLHandshakeException

将REST客户端与标头一起使用时获取ssl.SSLHandshakeException

慕田峪7331174 2021-05-14 14:42:57
我有一个外部REST资源,其中包含以下详细信息:网址:( abc.com/orders域位于https)我需要将UserID作为HTTP头传递,其键“ user”值为“ abcd”这将返回JSON响应我为此使用下面的Java代码:try {            Client client = Client.create();            WebResource webResource = client.resource("abc.com/orders");            ClientResponse response = webResource.header("user", "abcd").accept("application/json")                    .get(ClientResponse.class);            if (response.getStatus() != 200) {                throw new RuntimeException("Failed : HTTP error code : " + response.getStatus());            }            String output = response.getEntity(String.class);            System.out.println("Output from Server .... \n");            System.out.println(output);        } catch (Exception e) {            e.printStackTrace();        }但是我正在低于异常,尽管它可以正常工作 PostMancom.sun.jersey.api.client.ClientHandlerException: 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    at com.sun.jersey.client.urlconnection.URLConnectionClientHandler.handle(URLConnectionClientHandler.java:155)    at com.sun.jersey.api.client.Client.handle(Client.java:652)    at com.sun.jersey.api.client.WebResource.handle(WebResource.java:682)    at com.sun.jersey.api.client.WebResource.access$200(WebResource.java:74)    at com.sun.jersey.api.client.WebResource$Builder.get(WebResource.java:509)我尝试对其进行搜索,发现需要从该URL获取证书并将其添加到jdk/lib/security文件夹中的某个地方。但我不知道该如何进行。
查看完整描述

2 回答

?
BIG阳

TA贡献1859条经验 获得超6个赞

男子!不需要以上任何内容!!!只需RestAssured.useRelaxedHTTPSValidation();在Rest Api代码之前通过即可。完成!


查看完整回答
反对 回复 2021-05-26
  • 2 回答
  • 0 关注
  • 165 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信