3

我有一个证书(由 ca 签名)添加到我的信任库,但是当我尝试通过以下代码访问它时,我得到了异常,PKIX path validation failed: java.security.cert.CertPathValidatorException: Path does not chain with any of the trust anchors

代码:

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import javax.net.ssl.HttpsURLConnection;

public class ConnectHttps
{ 

public static void main(String[] argsd)
{
    System.out.println("***************Https testing started **************");


    try
    {
        URL u = new URL(
            "https://my-server.com/my-webservices/data");
        HttpsURLConnection http = (HttpsURLConnection) u.openConnection();
        http.setAllowUserInteraction(true);
        http.setRequestMethod("GET");
        http.connect();

        InputStream is = http.getInputStream();
        BufferedReader reader = new BufferedReader(new InputStreamReader(is));
        StringBuilder stringBuilder = new StringBuilder();
        String line = null;
        while ((line = reader.readLine()) != null)
        {
            stringBuilder.append(line
                + "\n");
        }
        System.out.println(stringBuilder.toString());
        System.out.println("***************Https testing completed **************");
    }
    catch (IOException e)
    {
        System.out.println("***************Https testing failed **************");
        e.printStackTrace();
    }
}

}

证书有效,并在谷歌浏览器上完美显示数据,即:

铬合金

但不是在 mozilla firefox 和我的 java 客户端(上):

火狐

请指教,可能是什么问题。

4

0 回答 0