HTTPS Java

java如何实现https访问

九三
338
2021-02-18 12:34:49
栏目: 编程语言

java如何实现https访问

利用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;

}

0
看了该问题的人还看了