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

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

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

    無為

    無為則可為,無為則至深!

      BlogJava :: 首頁 :: 聯系 :: 聚合  :: 管理
      190 Posts :: 291 Stories :: 258 Comments :: 0 Trackbacks
    這是<<java網絡編程>> 中客戶端的例子
    這本書里還有個服務器端的例子
    不過太長了,
    // URLGrab.java

    import java.io.*;
    import java.net.*;
    import javax.security.cert.Certificate;
    import com.sun.net.ssl.HttpsURLConnection;   // J2SDK 1.3

    // import java.net.ssl.HttpsURLConnection;      // J2SDK 1.4

    /**
     * A simple application that grabs the contents of an URL and dumps
     * them to a file. The URL may be a https URL. Some properties of the
     * connection are displayed to standard output.
     */
    public class URLGrab {

      /**
       * The location of the https protocol handler
       */
      private static final String PROTOCOL_HANDLERS = 
        "com.sun.net.ssl.internal.www.protocol";

      /**
       * Retrieves the contents and other information about a connection given
       * on the command line.
       * @param args the command line arguments
       * @throws Exception if something went wrong
       */
      public static void main(String args[]) throws Exception {
        System.setProperty("java.protocol.handler.pkgs", PROTOCOL_HANDLERS);

        if (args.length != 2) {
          System.out.println("Please give an URL and a filename.");
        } else {
          URLConnection urlConn = new URL(args[0]).openConnection();
          urlConn.connect();                 // connect to the server
          displayProperties(urlConn);        // display connection properties
          writeContents(urlConn, args[1]);   // write URL contents to file
        } 
      } 

      /**
       * Writes the contents of the URL to a file
       * @param urlConn The connection
       * @param filename The name of the file to write to
       * @throws IOException if a network or other I/O error occurred
       */
      private static void writeContents(URLConnection urlConn, 
                                        String filename) throws IOException {
        InputStream in = urlConn.getInputStream();
        OutputStream out = new FileOutputStream(filename);
        try {
          byte[] buffer = new byte[512];
          int bytesRead;
          while ((bytesRead = in.read(buffer)) > 0) {
            out.write(buffer, 0, bytesRead);
          } 
        } 
        finally {
          try {
            out.close();
          } catch (Exception e) { /* do nothing */
          } 
          try {
            in.close();
          } catch (Exception e) { /* do nothing */
          } 
        } 
      } 

      /**
       * Displays some URL connection properties
       * @param urlConn The connection
       */
      private static void displayProperties(URLConnection urlConn) {
        System.out.println("Content Length: " + urlConn.getContentLength());
        System.out.println("Content Type: " + urlConn.getContentType());
        System.out.println("Content Encoding: " + urlConn.getContentEncoding());
        if (urlConn instanceof HttpsURLConnection) {
          displaySecureProperties((HttpsURLConnection) urlConn);
        } 
      } 

      /**
       * Displays some https URL connection properties
       * @param urlConn The secure connection
       */
      private static void displaySecureProperties(HttpsURLConnection urlConn) {
        System.out.println("Cipher Suite: " + urlConn.getCipherSuite());
        Certificate[] chain = urlConn.getServerCertificateChain();
        for (int i = 0; chain != null && i < chain.length; i++) {
          System.out.println("Certificate #" + (i + 1) + ":\n" + chain[i]);
        } 
      } 
    }

    我試了一下,工作正常

    凡是有該標志的文章,都是該blog博主Caoer(草兒)原創,凡是索引、收藏
    、轉載請注明來處和原文作者。非常感謝。

    posted on 2005-12-14 13:06 草兒 閱讀(399) 評論(0)  編輯  收藏 所屬分類: Java編程經驗談
    主站蜘蛛池模板: 亚洲男人的天堂在线va拉文| 又黄又爽无遮挡免费视频| 久久精品7亚洲午夜a| 日韩在线一区二区三区免费视频| 全免费A级毛片免费看网站| 亚洲日韩久久综合中文字幕| 成人免费无码大片a毛片| 亚洲欧美成人av在线观看| 国产成人免费a在线资源| 特级毛片aaaa级毛片免费| 亚洲中文无韩国r级电影 | 一级特级女人18毛片免费视频| 国产免费久久精品| 污网站在线观看免费| 伊伊人成亚洲综合人网7777| 免费人成在线观看视频高潮| 久久精品亚洲精品国产色婷| 91在线视频免费播放| 亚洲AV电影天堂男人的天堂| 亚洲国产成人五月综合网 | a级在线免费观看| 亚洲第一成年人网站| 在线观看人成网站深夜免费| 免费大片黄在线观看| 亚洲va中文字幕无码久久| 99久久99这里只有免费费精品| 亚洲1区2区3区精华液| 亚洲熟妇中文字幕五十中出| 99久久免费中文字幕精品| 亚洲精品国产suv一区88| 四虎影视成人永久免费观看视频 | 亚洲美女视频一区| 国产在线观看xxxx免费| 久久精品国产亚洲AV电影| 国产精品久久久久久久久久免费| 青青青亚洲精品国产| 亚洲AV永久无码精品成人| 成人免费看吃奶视频网站| 99久久国产精品免费一区二区| 亚洲va成无码人在线观看| 亚洲中文字幕在线乱码|