java如何实现https访问

2614
2021/2/18 12:34:49
栏目: 编程语言
开发者测试专用服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

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;

}

辰迅云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

推荐阅读: java中case的用法是什么