利用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⑻"));
String line = "";
while((line = br.readLine()) != null){
result += line;
}
本文来源:https://www.yuntue.com/post/59853.html | 云服务器网,转载请注明出处!