一般讀網頁就是用URL...但是有時候碰到的機車事就是要讀https...
最近都用JSP在寫, 主要的好處是不用重起server就可以運行...
搭載功能上速度跟要修改可以快很多~
以下截取重點:
<%@page import="java.net.*, java.io.*, javax.net.ssl.*" %>
TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return null;
}
public void checkClientTrusted(
java.security.cert.X509Certificate[] certs, String authType) {
}
public void checkServerTrusted(
java.security.cert.X509Certificate[] certs, String authType) {
}
} };
// Install the all-trusting trust manager
try {
SSLContext sc = SSLContext.getInstance("SSL");
sc.init(null, trustAllCerts, new java.security.SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
} catch (Exception e3) { }
StringBuffer theURL = new StringBuffer();
//System.out.println(theURL.toString());
URL url = new URL(theURL.toString());
//url.openConnection();
BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream()));
while(br.ready()) {
String tmp2 = br.readLine();
}
---------------------------------------------------
後記...在爬文章時~ 看到了這一篇
http://ws.apache.org/xmlrpc/ssl.html
被說成是 "The quick and dirty solution"...XD
偶也知道正規要去弄keystore...可是那很麻煩阿~囧rz...
有時候被迫在一個無法掌握SERVER重啟運作的情況下的快解...
不過正規的也是要懂一下啦Q_Q...
沒有留言:
張貼留言