fork download
  1. public class HttpsClient{
  2.  
  3. public static void main(String[] args)
  4. {
  5. new HttpsClient().testIt();
  6. }
  7.  
  8. private void testIt(){
  9.  
  10. String https_url = "https://www.google.com/";
  11. URL url;
  12. try {
  13.  
  14. url = new URL(https_url);
  15. HttpsURLConnection con = (HttpsURLConnection)url.openConnection();
  16.  
  17. //dumpl all cert info
  18. print_https_cert(con);
  19.  
  20. //dump all the content
  21. print_content(con);
  22.  
  23. } catch (MalformedURLException e) {
  24. e.printStackTrace();
  25. } catch (IOException e) {
  26. e.printStackTrace();
  27. }
  28.  
  29. }
  30.  
  31. private void print_https_cert(HttpsURLConnection con){
  32.  
  33. if(con!=null){
  34.  
  35. try {
  36.  
  37. System.out.println("Response Code : " + con.getResponseCode());
  38. System.out.println("Cipher Suite : " + con.getCipherSuite());
  39. System.out.println("\n");
  40.  
  41. Certificate[] certs = con.getServerCertificates();
  42. for(Certificate cert : certs){
  43. System.out.println("Cert Type : " + cert.getType());
  44. System.out.println("Cert Hash Code : " + cert.hashCode());
  45. System.out.println("Cert Public Key Algorithm : " + cert.getPublicKey().getAlgorithm());
  46. System.out.println("Cert Public Key Format : " + cert.getPublicKey().getFormat());
  47. System.out.println("\n");
  48. }
  49.  
  50. } catch (SSLPeerUnverifiedException e) {
  51. e.printStackTrace();
  52. } catch (IOException e){
  53. e.printStackTrace();
  54. }
  55.  
  56. }
  57.  
  58. }
  59.  
  60. private void print_content(HttpsURLConnection con){
  61. if(con!=null){
  62.  
  63. try {
  64.  
  65. System.out.println("****** Content of the URL ********");
  66. new InputStreamReader(con.getInputStream()));
  67.  
  68. String input;
  69.  
  70. while ((input = br.readLine()) != null){
  71. System.out.println(input);
  72. }
  73. br.close();
  74.  
  75. } catch (IOException e) {
  76. e.printStackTrace();
  77. }
  78.  
  79. }
  80.  
  81. }
  82.  
  83. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:1: error: class HttpsClient is public, should be declared in a file named HttpsClient.java
public class HttpsClient{
       ^
Main.java:31: error: cannot find symbol
   private void print_https_cert(HttpsURLConnection con){
                                 ^
  symbol:   class HttpsURLConnection
  location: class HttpsClient
Main.java:60: error: cannot find symbol
   private void print_content(HttpsURLConnection con){
                              ^
  symbol:   class HttpsURLConnection
  location: class HttpsClient
Main.java:11: error: cannot find symbol
      URL url;
      ^
  symbol:   class URL
  location: class HttpsClient
Main.java:14: error: cannot find symbol
         url = new URL(https_url);
                   ^
  symbol:   class URL
  location: class HttpsClient
Main.java:15: error: cannot find symbol
	     HttpsURLConnection con = (HttpsURLConnection)url.openConnection();
	     ^
  symbol:   class HttpsURLConnection
  location: class HttpsClient
Main.java:15: error: cannot find symbol
	     HttpsURLConnection con = (HttpsURLConnection)url.openConnection();
	                               ^
  symbol:   class HttpsURLConnection
  location: class HttpsClient
Main.java:23: error: cannot find symbol
      } catch (MalformedURLException e) {
               ^
  symbol:   class MalformedURLException
  location: class HttpsClient
Main.java:25: error: cannot find symbol
      } catch (IOException e) {
               ^
  symbol:   class IOException
  location: class HttpsClient
Main.java:41: error: cannot find symbol
	Certificate[] certs = con.getServerCertificates();
	^
  symbol:   class Certificate
  location: class HttpsClient
Main.java:42: error: cannot find symbol
	for(Certificate cert : certs){
	    ^
  symbol:   class Certificate
  location: class HttpsClient
Main.java:50: error: cannot find symbol
	} catch (SSLPeerUnverifiedException e) {
	         ^
  symbol:   class SSLPeerUnverifiedException
  location: class HttpsClient
Main.java:52: error: cannot find symbol
	} catch (IOException e){
	         ^
  symbol:   class IOException
  location: class HttpsClient
Main.java:66: error: cannot find symbol
	   BufferedReader br = 
	   ^
  symbol:   class BufferedReader
  location: class HttpsClient
Main.java:67: error: cannot find symbol
		new BufferedReader(
		    ^
  symbol:   class BufferedReader
  location: class HttpsClient
Main.java:68: error: cannot find symbol
			new InputStreamReader(con.getInputStream()));
			    ^
  symbol:   class InputStreamReader
  location: class HttpsClient
Main.java:77: error: cannot find symbol
	} catch (IOException e) {
	         ^
  symbol:   class IOException
  location: class HttpsClient
17 errors
stdout
Standard output is empty