⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 httpsclient.java

📁 wendang for java. 124342423 432
💻 JAVA
字号:
package javasec.samples.ch14;import java.io.*;import java.net.*;import com.sun.net.ssl.*;public class HttpsClient {    static class HttpClientVerifier implements HostnameVerifier {        public boolean verify(String url, String cert) {            try {                // We know the strings don抰 match, but it抯                // conceivable that their IP addresses do.  We                // could also ask the user here.                InetAddress iaU = InetAddress.getByName(url);                InetAddress iaC = InetAddress.getByName(cert);                return iaU.equals(iaC);            } catch (Exception e) {                return false;            }        }    }    public static void main(String[] args) throws Exception {        URL u = new URL(args[0]);        // Alternately, we could set a global verifier like this        // HttpsURLConnection.setDefaultHostnameVerifier(        //                  new HttpClientVerifier());        HttpsURLConnection huc =                  (HttpsURLConnection) u.openConnection();        // Instead, we set the verifier only for this instance        huc.setHostnameVerifier(new HttpClientVerifier());        BufferedReader br = new BufferedReader(                        new InputStreamReader(huc.getInputStream()));        String s = br.readLine();        while (s != null) {            System.out.println(s);            s = br.readLine();        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -