我有一个证书(由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();
}
}
}
证书有效并在Google Chrome上完美显示数据,即:
但不是关于mozilla firefox和我的java客户端(上图):
请告知,可能是什么问题。