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

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

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

    少年阿賓

    那些青春的歲月

      BlogJava :: 首頁(yè) :: 聯(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 閱讀(1932) 評(píng)論(1)  編輯  收藏 所屬分類: httpClient

    Feedback

    # re: Java HTTPS Client – HttpsURLConnection Example 2014-09-27 21:55 help
    把地址改為https://member.my089.com/,程序報(bào)錯(cuò),是什么原因呢  回復(fù)  更多評(píng)論
      

    主站蜘蛛池模板: 亚洲国产精品人久久| 亚洲日韩在线中文字幕第一页| 亚洲国产AV无码一区二区三区| 亚洲av无码不卡| 亚洲欧洲自拍拍偷精品 美利坚| 无码乱肉视频免费大全合集 | 亚洲2022国产成人精品无码区 | 九九热久久免费视频| 亚洲免费综合色在线视频| 久久精品亚洲中文字幕无码麻豆 | 野花香在线视频免费观看大全| 一个人看的免费观看日本视频www| 亚洲精品人成网线在线播放va| 7777久久亚洲中文字幕| 亚洲精品在线电影| 日本久久久久亚洲中字幕| 亚洲国产二区三区久久| 国产∨亚洲V天堂无码久久久 | 人妻丰满熟妇无码区免费| 久久午夜夜伦鲁鲁片免费无码| 一级毛片免费在线| 国产精品免费看久久久香蕉| 中文字幕不卡免费高清视频| 国产免费网站看v片在线| 无码av免费一区二区三区| 57pao国产成视频免费播放| 4虎1515hh永久免费| 成熟女人牲交片免费观看视频| 日本免费xxxx色视频| 成人免费视频试看120秒| 亚洲AV无码不卡在线观看下载| 亚洲国产日韩成人综合天堂| 亚洲av无码av制服另类专区| 亚洲一级高清在线中文字幕| 亚洲av乱码一区二区三区按摩| 在线播放国产不卡免费视频| 三年片在线观看免费观看大全一| 日韩版码免费福利视频| 亚洲五月午夜免费在线视频| 亚洲国产成人超福利久久精品| 男女猛烈xx00免费视频试看|