https请求

Posted 也许还年轻

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了https请求相关的知识,希望对你有一定的参考价值。

 public List<HrOrgDTO> parseJson() {
        logger.info("===========parseJson======start");
        List list = null;
        BufferedReader is = null;
        HttpsURLConnection httpsConn = null;

        try {
            String e = this.sysConfig.getValue("YG_HR_URL");
            URL url = new URL(e);
            if(e.startsWith("https")) {
                SSLContext sb = SSLContext.getInstance("SSL");
                sb.init((KeyManager[])null, new TrustManager[]{new YgHrService.TrustAnyTrustManager()}, new SecureRandom());
                httpsConn = (HttpsURLConnection)url.openConnection();
                httpsConn.setSSLSocketFactory(sb.getSocketFactory());
                httpsConn.setHostnameVerifier(new YgHrService.TrustAnyHostnameVerifier());
                httpsConn.setDoOutput(true);
                httpsConn.connect();
                is = new BufferedReader(new InputStreamReader(httpsConn.getInputStream(), "UTF-8"));
            } else {
                is = new BufferedReader(new InputStreamReader(url.openStream(), "GBK"));
            }

            StringBuffer sb1 = new StringBuffer();
            String str = "";

            while((str = is.readLine()) != null) {
                sb1.append(str);
            }

            String src = sb1.toString().replaceAll(" ", "");
            src = src.substring(src.indexOf("([") + 1, src.length() - 1);
            list = JSONArray.parseArray(src, HrOrgDTO.class);
        } catch (Exception var17) {
            logger.error("========json转dto error", var17);
        } finally {
            if(is != null) {
                try {
                    is.close();
                } catch (Exception var16) {
                    ;
                }
            }

            if(httpsConn != null) {
                httpsConn.disconnect();
            }

        }

        logger.info("===========parseJson======end");
        return list;
    }

    public void truncateYgORGTable() {
        this.dao.truncateYgORGTable();
    }

    private static class TrustAnyHostnameVerifier implements HostnameVerifier {
        private TrustAnyHostnameVerifier() {
        }

        public boolean verify(String hostname, SSLSession session) {
            return true;
        }
    }

    private static class TrustAnyTrustManager implements X509TrustManager {
        private TrustAnyTrustManager() {
        }

        public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
        }

        public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
        }

        public void checkClientTrusted(java.security.cert.X509Certificate[] arg0, String arg1) throws java.security.cert.CertificateException {
        }

        public void checkServerTrusted(java.security.cert.X509Certificate[] arg0, String arg1) throws java.security.cert.CertificateException {
        }

        public java.security.cert.X509Certificate[] getAcceptedIssuers() {
            return null;
        }
    }

 

以上是关于https请求的主要内容,如果未能解决你的问题,请参考以下文章

VSCode自定义代码片段14——Vue的axios网络请求封装

VSCode自定义代码片段14——Vue的axios网络请求封装

Android App 安全的HTTPS 通信

C#-WebForm-★内置对象简介★Request-获取请求对象Response相应请求对象Session全局变量(私有)Cookie全局变量(私有)Application全局公共变量Vi(代码片段

c# https请求忽略证书验证_各种编程语言忽略http的SSL证书认证

简单的 Javascript http 请求片段但不起作用