利用java實現https訪問,具體方法如下:
String result = "";
URL url = new URL("網址");
HttpsURLConnection conn = (HttpsURLConnection)url.openConnection();
conn.setDoInput(true);
conn.setSSLSocketFactory(sslSocketFactory);
conn.setHostNameVerifier(new HostNameVerifier(){
public boolean verify(String hostName, SSLSession session){
return true;
}
});
conn.connect();
BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream(), "utf-8"));
String line = "";
while((line = br.readLine()) != null){
result += line;
}