package javaapplication1;
import java.net.MalformedURLException;
import java.net.URL;
import java.io.*;
import javax.net.ssl.HttpsURLConnection;
public class JavaApplication1 {
public static void main(String[] args) {
System.out.println(new JavaApplication1().https_connect("https://en.wikipedia.org/wiki/HTTPS"));
}
private String https_connect(String https_url) {
URL url;
try {
url = new URL(https_url);
HttpsURLConnection con = (HttpsURLConnection) url.openConnection();
con.addRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)");
return get_content(con);
} catch (MalformedURLException e) {
System.out.println(e.getMessage());
} catch (IOException e) {
System.out.println(e.getMessage());
}
return "Error";
}
private String get_content(HttpsURLConnection con) {
String html = "";
if (con != null) {
try {
BufferedReader br = new BufferedReader(
new InputStreamReader(con.getInputStream()));
String line;
while ((line = br.readLine()) != null) {
html = html + "\r\n" + line;
}
br.close();
} catch (IOException e) {
System.out.println(e.getMessage());
}
}
return html;
}
}
/*
run:
<!DOCTYPE html>
<html lang="en" dir="ltr" class="client-nojs">
<head>
<meta charset="UTF-8"/>
<title>HTTPS - Wikipedia, the free encyclopedia</title>
<script>document.documentElement.className = document.documentElement.className...
...
*/