关于获取https服务器的问题,java用的方法是:
URL urL;
try {
urL = new URL(hsUrl);
HttpsURLConnection con = (HttpsURLConnection) urL.openConnection();
X509TrustManager xtm = new X509TrustManager() {
@
Override public X509Certificate[] getAcceptedIssuers() {
// TODO Auto-generated method stub
return null;
}
@
Override public void checkServerTrusted(X509Certificate[] arg0,
String arg1) throws CertificateException {
// TODO Auto-generated method stub
}
@
Override public void checkClientTrusted(X509Certificate[] arg0,
String arg1) throws CertificateException {
// TODO Auto-generated method stub
}
};
TrustManager[] tm = { xtm };
SSLContext ctx = SSLContext.getInstance("TLS");
ctx.init(null, tm, null);
con.setSSLSocketFactory(ctx.getSocketFactory());
con.setHostnameVerifier(new HostnameVerifier() {
@
Override public boolean verify(String arg0, SSLSession arg1) {
return true;
}
});
InputStream ss = con.getInputStream();
DataInputStream in = new DataInputStream(ss);
String re;
while ((re = in.readLine()) != null) {
System.out.println(re);
break;
}
in.close();
找了很多天解决办法了, - -心都碎了。