Ash*_*win 5 java ssl https certificate
我在服务器和客户端之间建立了一个https连接,其中客户端是一个java程序,服务器是一个servlet.我使用以下代码从服务器打印证书详细信息.
URL url = new URL("https://localhost:8443/cert");
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
connection.setSSLSocketFactory(sslsocketfactory);
connection.setDoOutput(true);
if(connection!=null){
Certificate[] certs = connection.getServerCertificates();// #1
System.out.println("Cert Type : " + certs[0].getType());
System.out.println("Cert Hash Code : " + certs[0].hashCode());
System.out.println("Cert Public Key Algorithm : " + certs[0].getPublicKey().getAlgorithm());
System.out.println("Cert Public Key Format : " + certs[0].getPublicKey().getFormat());
System.out.println("\n");
}
Run Code Online (Sandbox Code Playgroud)
但我得到以下例外.
java.lang.IllegalStateException: connection not yet open
Run Code Online (Sandbox Code Playgroud)
我认为握手应该在调用theurl.openconnection()方法时立即进行.这里有什么问题?
异常抛出行号'#1'(参见上面代码中的注释)
| 归档时间: |
|
| 查看次数: |
4717 次 |
| 最近记录: |