How to ignore PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException?

前端 未结 8 705
旧巷少年郎
旧巷少年郎 2020-11-28 03:29

I got the following exception when try to post a request to a http server:

Here is the code I used

URL url = new URL(
        \"https://www.abc.com\"         


        
8条回答
  •  春和景丽
    2020-11-28 04:08

    If you want to ignore the certificate all together then take a look at the answer here: Ignore self-signed ssl cert using Jersey Client

    Although this will make your app vulnerable to man-in-the-middle attacks.

    Or, try adding the cert to your java store as a trusted cert. This site may be helpful. http://blog.icodejava.com/tag/get-public-key-of-ssl-certificate-in-java/

    Here's another thread showing how to add a cert to your store. Java SSL connect, add server cert to keystore programmatically

    The key is:

    KeyStore.Entry newEntry = new KeyStore.TrustedCertificateEntry(someCert);
    ks.setEntry("someAlias", newEntry, null);
    

提交回复
热议问题