小编J. *_*Doe的帖子

使用带有标头的 REST 客户端时获取 ssl.SSLHandshakeException 但与 PostMan 一起工作正常

我有一个包含以下详细信息的外部 REST 资源:

  1. 网址:( abc.com/orders域名为https
  2. 我需要将 UserID 作为 HTTP 标头传递,键“user”值为“abcd”
  3. 这将返回一个 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();

        }
Run Code Online (Sandbox Code Playgroud)

但是我得到了低于异常的结果,尽管它可以正常工作 PostMan

com.sun.jersey.api.client.ClientHandlerException: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable …
Run Code Online (Sandbox Code Playgroud)

java rest jersey rest-client

6
推荐指数
2
解决办法
1万
查看次数

标签 统计

java ×1

jersey ×1

rest ×1

rest-client ×1