Wednesday, July 13, 2011

java download remote certificate

In one of my project, I need a certificate from the server which provides web service over https. The server can only be visited from a unix box which cannot run firefox, IE…

The java code below can download the certificate. Note, the certificate must be signed by a trusted certification provider, like versign. Otherwise, like self signed certificate, it won’t allow you establish the connection.

URL url = new URL("");
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("", 8080));
HttpsURLConnection con = (HttpsURLConnection) url.openConnection();
Certificate certs[] = con.getServerCertificates();
for (Certificate cert : certs) {
Method getEncoded() of Certificate returns byte[] which allows you save it in a file.


a blog from internet api

Using proxy in http connection

No comments:

Post a Comment