httpclien调用skipHttpsUtil得wrapClient方法跳过https证书验证

SkipHttpsUtil  skipHttpsUtil=new SkipHttpsUtil();
            CloseableHttpClient httpclient = null;
            CloseableHttpResponse response = null;
            try {
                httpclient =  (CloseableHttpClient)skipHttpsUtil.wrapClient();
                HttpPost post = new HttpPost(url);
                String json = "{\"image\":\""+"ddd"+
                        "\",\"Type\":\""+"ddddd"+
                        "\",\"Flag\":\""+"dddd"+"\"}";    
                StringEntity postingString = new StringEntity(json,"utf-8");// json传递  
                post.setEntity(postingString);
                post.setHeader("Content-type", "application/json");                              
                response = httpclient.execute(post);    
                String result = EntityUtils.toString(response.getEntity());
                JSONObject js=JSONObject.parseObject(result);

} catch (Exception e) {
                e.printStackTrace();
                mResultCode = "E";
                return false;
            } finally {
                try {
                    response.close();
                       httpclient.close();
                } catch (IOException e) {
                    e.printStackTrace();
                    mResultCode = "E";
                    return false;
                }
                
            }

skipHttpsUtil类

package com.life.util;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;

import org.apache.http.client.HttpClient;
import org.apache.http.conn.ssl.NoopHostnameVerifier;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.log4j.Logger;

/**
 * <p>
 * ClassName: SkipHttpsUtil
 * </p>
 * <p>
 * Description: httpclient跳过https验证
 * </p>
 * <p>
 * Copyright: Copyright (c) 2019
 * </p>
 * <p>
 * Company: service
 * </p>
 * @author: maojinqiang
 * @CreateDate: 2019-08-26
 */
public class SkipHttpsUtil {
    private static Logger logger = Logger.getLogger(SkipHttpsUtil.class);
    //绕过证书
    public static HttpClient wrapClient() {
        try {
            SSLContext ctx = SSLContext.getInstance("TLS");
            X509TrustManager tm = new X509TrustManager() {
                public X509Certificate[] getAcceptedIssuers() {
                    return null;
                }
 
                public void checkClientTrusted(X509Certificate[] arg0,
                        String arg1) throws CertificateException {
                }
 
                public void checkServerTrusted(X509Certificate[] arg0,
                        String arg1) throws CertificateException {
                }
            };
            ctx.init(null, new TrustManager[] { tm }, null);
            SSLConnectionSocketFactory ssf = new SSLConnectionSocketFactory(
                    ctx, NoopHostnameVerifier.INSTANCE);
            CloseableHttpClient httpclient = HttpClients.custom()
                    .setSSLSocketFactory(ssf).build();
            return httpclient;
        } catch (Exception e) {
            return HttpClients.createDefault();
        }
    }   
    public static void main(String[] args) {

}
}

java httpclient跳过https证书验证的更多相关文章

  1. linux 测试 get 请求 跳过SSL证书验证

    Linux 下测试 get 请求: curl : curl "http://www.qq.com" # 标准输出页面内容 curl -i "http://www.qq.c ...

  2. Retrofit+OKHttp忽略https证书验证

    记录这个的原因,是因为很多时候,因为后台配置的证书不正确导致APP访问不到服务器数据,导致影响自身的开发进度.没几行代码,逻辑也清晰,所以下面就直接贴出工具类吧: package huolongluo ...

  3. 网络基础 记一次HTTPS证书验证测试过程

    记一次HTTPS证书验证测试过程 by:授客 QQ:1033553122 实践 1) 安装证书 选择主机A(假设10.202.95.88)上安装https证书 说明:采用https的服务器,必须安装数 ...

  4. 解决https证书验证不通过的问题

    1.报错信息 java.security.cert.CertificateException: No name matching api.weibo.com found; nested excepti ...

  5. .net core中引用webservice,并忽略https证书验证

    1.打开vs, 工具-->扩展和更新 下载这个 2. 在admin下右键,添加-->connected service 选择wsdl文件路径,或者服务的url,比如https://**** ...

  6. 解决 https 证书验证不通过的问题

    解决的办法:忽略服务端和客户端的证书校验即可.java 提供的相关的类. 通过重写TrustManager的checkClientTrusted(检查客户端证书信任)和checkServerTrust ...

  7. 【腾讯Bugly干货分享】iOS 中 HTTPS 证书验证浅析

    本文来自于腾讯Bugly公众号(weixinBugly),未经作者同意,请勿转载,原文地址:https://mp.weixin.qq.com/s/-fLLTtip509K6pNOTkflPQ 导语 本 ...

  8. UIWebView 跳过HTTPS证书认证

    UIWebView跳过证书认证 在UIWebView中加入如下代码即可(Error Domain=NSURLErrorDomain Code=-1202) //跳过证书验证 @interface NS ...

  9. iOS 绕过https证书验证 请求数据

    HTTPS和HTTP: 1.https协议需要到ca申请证书,一般免费证书很少,需要交费. 2.http是超文本传输协议,信息是明文传输,https 则是具有安全性的ssl加密传输协议. 3.http ...

随机推荐

  1. Apache性能测试工具ab使用详解~转载

    Apache自带性能测试工具ab使用详解 一. Apache的下载 1. http://www.apache.org/,进入Apache的官网 2. 将页面拖到最下方“Apache Project L ...

  2. 关于js-xlsx的使用

    写在前头,本人是名Java开发人员,偶尔在前端打打酱油,写出的代码或许存在问题,请路过的大神一一指正,不吝感激. 最近公司准备做一些关于Excel 数据导入和导出相关需求,之前有在开源社区看到说比起纯 ...

  3. html页面中关于按钮type的要求

    重要事项:如果在 HTML 表单中使用 button 元素,不同的浏览器会提交不同的值.Internet Explorer 将提交 <button> 与 </button> 之 ...

  4. 【CSS】Houdini, CSS的成人礼

    前情提要 CSS:老板,你看ES9,ES10都出来了,您看我的事情什么时候... W3C: 这不是正在走着流程嘛!小C你不要心急! W3C:(语重心长)你看啊,我们先(1)提个开发提案章程, 然后再批 ...

  5. Java 从入门到进阶之路(三)

    之前的文章我们介绍了 Java 中的变量和基本数据类型,本章我们来看一下 Java 的运算符和表达式. 计算机的最基本用途之一就是执行数学运算,作为一门计算机语言,Java也提供了一套丰富的运算符来操 ...

  6. Python之变量、常量以及注释

    Python之变量.常量以及注释 一.什么是变量 变量,是用于在内存中存放程序数据的容器,怎么理解呢? 计算机的最核心的功能j就是"计算",计算需要数据源,数据源存在在内存里,比如 ...

  7. python 07 数据类型

    目录 1. 基础数据类型填充 1.str:(不可变) 2. list: 3. tuple: 4. dict: 5. set: 6. bool: 7. 数据类型之间转换 2.删除列表/字典的代码坑: 3 ...

  8. Nginx和Apache各自的优缺点

    nginx 相对 apache 的优点: 轻量级,同样起web 服务,比apache 占用更少的内存及资源 抗并发,nginx 处理请求是异步非阻塞的,而apache 则是阻塞型的,在高并发下ngin ...

  9. Leetcode之深度优先搜索&回溯专题-679. 24 点游戏(24 Game)

    Leetcode之深度优先搜索&回溯专题-679. 24 点游戏(24 Game) 深度优先搜索的解题详细介绍,点击 你有 4 张写有 1 到 9 数字的牌.你需要判断是否能通过 *,/,+, ...

  10. MySQL 5.7 的安装历程

    mysql5.7零基础入门级的安装教程: 安装环境:Windows 10, 64 位(联想拯救者R720) 安装版本:mysql-5.7.25-winx64 一.下载 1.进入官网 首先,下载MySQ ...