<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    少年阿賓

    那些青春的歲月

      BlogJava :: 首頁 :: 聯(lián)系 :: 聚合  :: 管理
      500 Posts :: 0 Stories :: 135 Comments :: 0 Trackbacks

    Here’s a simple Java HTTPS client to demonstrate the use of HttpsURLConnection class to print a https URL content and certificate detail.

    Access https URL : https://www.google.com/


    package com.mkyong.client;
     
    import java.net.MalformedURLException;
    import java.net.URL;
    import java.security.cert.Certificate;
    import java.io.*;
     
    import javax.net.ssl.HttpsURLConnection;
    import javax.net.ssl.SSLPeerUnverifiedException;
     
    public class HttpsClient{
     
       public static void main(String[] args)
       {
            new HttpsClient().testIt();
       }
     
       private void testIt(){
     
          String https_url = "https://www.google.com/";
          URL url;
          try {
     
    	     url = new URL(https_url);
    	     HttpsURLConnection con = (HttpsURLConnection)url.openConnection();
     
    	     //dumpl all cert info
    	     print_https_cert(con);
     
    	     //dump all the content
    	     print_content(con);
     
          } catch (MalformedURLException e) {
    	     e.printStackTrace();
          } catch (IOException e) {
    	     e.printStackTrace();
          }
     
       }
     
       private void print_https_cert(HttpsURLConnection con){
     
        if(con!=null){
     
          try {
     
    	System.out.println("Response Code : " + con.getResponseCode());
    	System.out.println("Cipher Suite : " + con.getCipherSuite());
    	System.out.println("\n");
     
    	Certificate[] certs = con.getServerCertificates();
    	for(Certificate cert : certs){
    	   System.out.println("Cert Type : " + cert.getType());
    	   System.out.println("Cert Hash Code : " + cert.hashCode());
    	   System.out.println("Cert Public Key Algorithm : " + cert.getPublicKey().getAlgorithm());
    	   System.out.println("Cert Public Key Format : " + cert.getPublicKey().getFormat());
    	   System.out.println("\n");
    	}
     
    	} catch (SSLPeerUnverifiedException e) {
    		e.printStackTrace();
    	} catch (IOException e){
    		e.printStackTrace();
    	}
     
         }
     
       }
     
       private void print_content(HttpsURLConnection con){
    	if(con!=null){
     
    	try {
     
    	   System.out.println("****** Content of the URL ********");			
    	   BufferedReader br = 
    		new BufferedReader(
    			new InputStreamReader(con.getInputStream()));
     
    	   String input;
     
    	   while ((input = br.readLine()) != null){
    	      System.out.println(input);
    	   }
    	   br.close();
     
    	} catch (IOException e) {
    	   e.printStackTrace();
    	}
     
           }
     
       }
     
    }

    Output…

    Response Code : 200
    Cipher Suite : SSL_RSA_WITH_RC4_128_SHA
     
    Cert Type : X.509
    Cert Hash Code : 7810131
    Cert Public Key Algorithm : RSA
    Cert Public Key Format : X.509
     
    Cert Type : X.509
    Cert Hash Code : 6042770
    Cert Public Key Algorithm : RSA
    Cert Public Key Format : X.509
     
    ****** Content of the URL ********
    <!doctype html><html><head><meta http-equiv="content-type" ......
    posted on 2012-08-16 00:17 abin 閱讀(1933) 評論(1)  編輯  收藏 所屬分類: httpClient

    Feedback

    # re: Java HTTPS Client – HttpsURLConnection Example 2014-09-27 21:55 help
    把地址改為https://member.my089.com/,程序報錯,是什么原因呢  回復  更多評論
      

    主站蜘蛛池模板: 99在线热播精品免费99热| 啊灬啊灬别停啊灬用力啊免费看| 男女作爱免费网站| 成人免费a级毛片| www亚洲精品少妇裸乳一区二区| 日韩精品免费一区二区三区| 亚洲sss综合天堂久久久| 亚洲欧美日韩中文字幕一区二区三区 | 国产亚洲精品免费视频播放| 亚洲黄色免费电影| 国产成人精品免费视频软件| MM1313亚洲国产精品| 免费在线观看一级毛片| 国产特黄特色的大片观看免费视频| 亚洲视频在线一区二区| 中文字幕乱码系列免费| 亚洲色图在线播放| 精品女同一区二区三区免费播放 | 国产人妖ts在线观看免费视频| 亚洲欧好州第一的日产suv| 国产一区二区三区在线观看免费| 香蕉视频在线观看免费| 亚洲一区二区三区自拍公司| 99精品视频在线免费观看| 激情综合亚洲色婷婷五月| 久久久久国色AV免费观看| 亚洲乱码无码永久不卡在线| 99久久人妻精品免费一区| 亚洲综合一区国产精品| 最刺激黄a大片免费网站| 久久香蕉国产线看观看亚洲片| 13一14周岁毛片免费| 国产精品亚洲一区二区三区在线观看| 久久久久亚洲精品中文字幕| 91福利免费视频| 黄色三级三级三级免费看| 久久精品亚洲中文字幕无码网站| 最近最好的中文字幕2019免费| 黄 色一级 成 人网站免费| 亚洲妇女水蜜桃av网网站| 色片在线免费观看|