我无法从我的网站(其他网站)获取证书。我尝试了一些解决方案HttpsURLConnection
和方法getServerCertificates
但没有任何办法可以解决问题。
URL httpsURL = new URL("https://www.google.com.br/");
HttpsURLConnection connection = (HttpsURLConnection)httpsURL.openConnection();
Certificate[] certs = connection.getServerCertificates();
我收到异常消息“无法解析 getServerCertificates”。
我认为没有必要使用密钥库,是吗?
我收到一个异常,说 getServerCertificates 无法解析。
真奇怪。您确定您使用的是正确的类吗?如果我运行这段代码:
import java.io.IOException;
import java.net.URL;
import java.security.cert.Certificate;
import javax.net.ssl.HttpsURLConnection;
public class Test {
public static void main(String[] args) throws IOException {
URL httpsURL = new URL("https://www.google.com.br/");
HttpsURLConnection connection = (HttpsURLConnection) httpsURL.openConnection();
connection.connect();
Certificate[] certs = connection.getServerCertificates();
for (Certificate cer : certs) {
System.out.println(cer.getPublicKey());
}
}
}
我得到的结果如下:
Sun RSA public key, 1024 bits
modulus: 13069990984429476578...
public exponent: 65537
Sun RSA public key, 1024 bits
modulus: 14179907349200548596...
public exponent: 65537
验证您使用的 SSL 套接字工厂,也许有问题。将其添加到您的代码中并查看它的结果(例如,对我来说是com.sun.net.ssl.internal.ssl.SSLSocketFactoryImpl
):
System.out.println(connection.getSSLSocketFactory().getClass());
System.out.println(connection.getDefaultSSLSocketFactory().getClass());
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)