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. 《深入理解Java虚拟机》- JVM如何进行异常处理

    一.Java异常 在程序中,错误可能产生于程序员没有预料到的各种情况,或者超出程序员可控范围的环境,例如用户的坏数据.试图打开一个不存在的文件等.为了能够及时有效地处理程序中的运行错误,Java 专门 ...

  2. 基于mybatisPlus的特殊字符校验

    要实现以下代码前提是导入Mybatis-plus的jar: * @author WENGKAIBO505 */ @Target({ElementType.FIELD, ElementType.METH ...

  3. springBoot配置activeMq点对点模式消费信息以及独占模式消费如何设置

    1.在pom文件中引入对应jar包 <!--activeMQ start--> <dependency> <groupId>org.springframework. ...

  4. HillCrest Sensor HAL

    1. 抽象定义 Google为Sensor提供了统一的HAL接口,不同的硬件厂商需要根据该接口来实现并完成具体的硬件抽象层,Android中Sensor的HAL接口定义在:hardware/libha ...

  5. python 23 继承

    目录 继承--inheritance 1. 面向对象继承: 2. 单继承 2.1 类名执行父类的属性.方法 2.2 子类对象执行父类的属性.方法 2.3 执行顺序 2.4 既要执行子类的方法,又要执行 ...

  6. FZU - 1914

    题意略. 思路: 我们应该着重关注负数对当前数列的影响,由于前缀和的性质,我们都是从当前数字向前加,这其实也是在枚举以哪个下标作为开头. 详见代码: #include<stdio.h> # ...

  7. Mysql根据出生日期计算年龄五种方法比较

    方法一 SELECT DATE_FORMAT(FROM_DAYS(TO_DAYS(NOW())-TO_DAYS(birthday)), '%Y')+0 AS age 方法一缺陷,就是当日期为未来日期时 ...

  8. P1603 斯诺登的密码-字符串加法的妙用

    传送门:https://www.luogu.org/problemnew/show/P1603 题意: 首先在给定的字符串中,找出特定的单词,把它转化成特定的数字, 然后在这些数字中,找出排列结果最小 ...

  9. CodeForces 931E Game with String

    Game with String 题意:有一个字符串,可以选择从第K位开始,将[K,len(s)-1]的字符都移到前面去,现在给你一个首字母,你可以再选择一位进行观察,然后猜测这个K的值是多少, 现在 ...

  10. Investigating Div-Sum Property UVA - 11361

    An integer is divisible by 3 if the sum of its digits is also divisible by 3. For example, 3702 is d ...