当前位置: 首页>>代码示例>>Java>>正文


Java HttpsURLConnection类代码示例

本文整理汇总了Java中com.sun.net.ssl.HttpsURLConnection的典型用法代码示例。如果您正苦于以下问题:Java HttpsURLConnection类的具体用法?Java HttpsURLConnection怎么用?Java HttpsURLConnection使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


HttpsURLConnection类属于com.sun.net.ssl包,在下文中一共展示了HttpsURLConnection类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: doClientSide

import com.sun.net.ssl.HttpsURLConnection; //导入依赖的package包/类
void doClientSide() throws Exception {
    /*
     * Wait for server to get started.
     */
    while (!serverReady) {
        Thread.sleep(50);
    }

    HostnameVerifier reservedHV =
        HttpsURLConnection.getDefaultHostnameVerifier();
    try {
        System.setProperty("java.protocol.handler.pkgs",
            "com.sun.net.ssl.internal.www.protocol");
        HttpsURLConnection.setDefaultHostnameVerifier(new NameVerifier());

        URL url = new URL("https://" + "localhost:" + serverPort +
                                "/etc/hosts");
        URLConnection urlc = url.openConnection();

        if (!(urlc instanceof com.sun.net.ssl.HttpsURLConnection)) {
            throw new Exception(
                "URLConnection ! instanceof " +
                "com.sun.net.ssl.HttpsURLConnection");
        }

        BufferedReader in = null;
        try {
            in = new BufferedReader(new InputStreamReader(
                               urlc.getInputStream()));
            String inputLine;
            System.out.print("Client reading... ");
            while ((inputLine = in.readLine()) != null)
                System.out.println(inputLine);

            System.out.println("Cipher Suite: " +
                ((HttpsURLConnection)urlc).getCipherSuite());
            X509Certificate[] certs =
                ((HttpsURLConnection)urlc).getServerCertificateChain();
            for (int i = 0; i < certs.length; i++) {
                System.out.println(certs[0]);
            }

            in.close();
        } catch (SSLException e) {
            if (in != null)
                in.close();
            throw e;
        }
        System.out.println("Client reports:  SUCCESS");
    } finally {
        HttpsURLConnection.setDefaultHostnameVerifier(reservedHV);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:54,代码来源:ComHTTPSConnection.java

示例2: doClientSide

import com.sun.net.ssl.HttpsURLConnection; //导入依赖的package包/类
void doClientSide() throws Exception {
    /*
     * Wait for server to get started.
     */
    while (!serverReady) {
        Thread.sleep(50);
    }

    System.setProperty("java.protocol.handler.pkgs",
        "com.sun.net.ssl.internal.www.protocol");

    System.setProperty("https.cipherSuites",
            "SSL_DH_anon_WITH_3DES_EDE_CBC_SHA");

    // use the default hostname verifier

    URL url = new URL("https://" + "localhost:" + serverPort +
                            "/etc/hosts");
    URLConnection urlc = url.openConnection();

    if (!(urlc instanceof com.sun.net.ssl.HttpsURLConnection)) {
        throw new Exception(
            "URLConnection ! instanceof " +
            "com.sun.net.ssl.HttpsURLConnection");
    }

    BufferedReader in = null;
    try {
        in = new BufferedReader(new InputStreamReader(
                           urlc.getInputStream()));
        String inputLine;
        System.out.print("Client reading... ");
        while ((inputLine = in.readLine()) != null)
            System.out.println(inputLine);
        System.out.println("Cipher Suite: " +
            ((HttpsURLConnection)urlc).getCipherSuite());
        in.close();
    } catch (SSLException e) {
        if (in != null)
            in.close();
        throw e;
    }
    System.out.println("Client reports:  SUCCESS");
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:45,代码来源:ComHostnameVerifier.java

示例3: doClientSide

import com.sun.net.ssl.HttpsURLConnection; //导入依赖的package包/类
void doClientSide() throws Exception {
    /*
     * Wait for server to get started.
     */
    while (!serverReady) {
        Thread.sleep(50);
    }

    HostnameVerifier reservedHV =
        HttpsURLConnection.getDefaultHostnameVerifier();
    try {
        URL.setURLStreamHandlerFactory(new ComSunHTTPSHandlerFactory());
        HttpsURLConnection.setDefaultHostnameVerifier(new NameVerifier());

        URL url = new URL("https://" + "localhost:" + serverPort +
                                "/etc/hosts");
        URLConnection urlc = url.openConnection();

        if (!(urlc instanceof com.sun.net.ssl.HttpsURLConnection)) {
            throw new Exception(
                "URLConnection ! instanceof " +
                "com.sun.net.ssl.HttpsURLConnection");
        }

        BufferedReader in = null;
        try {
            in = new BufferedReader(new InputStreamReader(
                               urlc.getInputStream()));
            String inputLine;
            System.out.print("Client reading... ");
            while ((inputLine = in.readLine()) != null)
                System.out.println(inputLine);

            System.out.println("Cipher Suite: " +
                ((HttpsURLConnection)urlc).getCipherSuite());
            Certificate[] certs =
                ((HttpsURLConnection)urlc).getServerCertificates();
            for (int i = 0; i < certs.length; i++) {
                System.out.println(certs[0]);
            }

            in.close();
        } catch (SSLException e) {
            if (in != null)
                in.close();
            throw e;
        }
        System.out.println("Client reports:  SUCCESS");
    } finally {
        HttpsURLConnection.setDefaultHostnameVerifier(reservedHV);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:53,代码来源:ComHTTPSConnection.java

示例4: doClientSide

import com.sun.net.ssl.HttpsURLConnection; //导入依赖的package包/类
void doClientSide() throws Exception {
    /*
     * Wait for server to get started.
     */
    while (!serverReady) {
        Thread.sleep(50);
    }

    URL.setURLStreamHandlerFactory(new ComSunHTTPSHandlerFactory());

    System.setProperty("https.cipherSuites",
            "SSL_DH_anon_WITH_3DES_EDE_CBC_SHA");

    // use the default hostname verifier

    URL url = new URL("https://" + "localhost:" + serverPort +
                            "/etc/hosts");
    URLConnection urlc = url.openConnection();

    if (!(urlc instanceof com.sun.net.ssl.HttpsURLConnection)) {
        throw new Exception(
            "URLConnection ! instanceof " +
            "com.sun.net.ssl.HttpsURLConnection");
    }

    BufferedReader in = null;
    try {
        in = new BufferedReader(new InputStreamReader(
                           urlc.getInputStream()));
        String inputLine;
        System.out.print("Client reading... ");
        while ((inputLine = in.readLine()) != null)
            System.out.println(inputLine);
        System.out.println("Cipher Suite: " +
            ((HttpsURLConnection)urlc).getCipherSuite());
        in.close();
    } catch (SSLException e) {
        if (in != null)
            in.close();
        throw e;
    }
    System.out.println("Client reports:  SUCCESS");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:44,代码来源:ComHostnameVerifier.java

示例5: doClientSide

import com.sun.net.ssl.HttpsURLConnection; //导入依赖的package包/类
void doClientSide() throws Exception {
    /*
     * Wait for server to get started.
     */
    while (!serverReady) {
        Thread.sleep(50);
    }

    System.setProperty("java.protocol.handler.pkgs",
        "com.sun.net.ssl.internal.www.protocol");
    HttpsURLConnection.setDefaultHostnameVerifier(new NameVerifier());

    URL url = new URL("https://" + "localhost:" + serverPort +
                            "/etc/hosts");
    URLConnection urlc = url.openConnection();

    if (!(urlc instanceof com.sun.net.ssl.HttpsURLConnection)) {
        throw new Exception(
            "URLConnection ! instanceof " +
            "com.sun.net.ssl.HttpsURLConnection");
    }

    BufferedReader in = null;
    try {
        in = new BufferedReader(new InputStreamReader(
                           urlc.getInputStream()));
        String inputLine;
        System.out.print("Client reading... ");
        while ((inputLine = in.readLine()) != null)
            System.out.println(inputLine);

        System.out.println("Cipher Suite: " +
            ((HttpsURLConnection)urlc).getCipherSuite());
        X509Certificate[] certs =
            ((HttpsURLConnection)urlc).getServerCertificateChain();
        for (int i = 0; i < certs.length; i++) {
            System.out.println(certs[0]);
        }

        in.close();
    } catch (SSLException e) {
        if (in != null)
            in.close();
        throw e;
    }
    System.out.println("Client reports:  SUCCESS");
}
 
开发者ID:openjdk,项目名称:jdk7-jdk,代码行数:48,代码来源:ComHTTPSConnection.java


注:本文中的com.sun.net.ssl.HttpsURLConnection类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。