Unable to find valid certification path to requested target - java

前端 未结 2 775
独厮守ぢ
独厮守ぢ 2021-02-05 16:56

I\'m trying to connect to a website using a HttpClient object. It works fine for websites we normally use(Like google). But there is a web site, when I try to connect, my progra

2条回答
  •  野的像风
    2021-02-05 17:43

    Problem was solved when I used a TrustSelfSignedStrategy object as the Trust material to HttpClient.

            httpClient = HttpClients.custom()
                .setSSLSocketFactory(new SSLConnectionSocketFactory(SSLContexts.custom()
                        .loadTrustMaterial(null, new TrustSelfSignedStrategy())
                        .build()
                    )
                ).build();
    

    The code I used is shown above..

提交回复
热议问题