RestTemplate 发送 Https 请求调用

个人博客:https://jacob.org.cn

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.http.ssl.SSLContextBuilder;
import org.apache.http.ssl.TrustStrategy;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;import javax.net.ssl.SSLContext;
import java.security.KeyManagementException;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;/*** @Classname RestTemplateUtils* @Description TODO* @Date 2020/6/30 18:09* @Created by wuzhiqian*/
public class RestTemplateUtils {public static RestTemplate getRestTemplate() throws KeyStoreException, NoSuchAlgorithmException, KeyManagementException {SSLContext sslContext = new SSLContextBuilder().loadTrustMaterial(null, new TrustStrategy() {@Overridepublic boolean isTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {return true;}}).build();SSLConnectionSocketFactory csf = new SSLConnectionSocketFactory(sslContext,new String[]{"TLSv1"},null,NoopHostnameVerifier.INSTANCE);CloseableHttpClient httpClient = HttpClients.custom().setSSLSocketFactory(csf).build();HttpComponentsClientHttpRequestFactory requestFactory =new HttpComponentsClientHttpRequestFactory();requestFactory.setHttpClient(httpClient);RestTemplate restTemplate = new RestTemplate(requestFactory);return restTemplate;}
}

RestTemplate 发送 Https 请求调用相关推荐

  1. springboot 使用restTemplate 发送https请求 忽略ssl证书

    最近在写接口的时候给对方回推数据,发送https请求的时候遇到这么个报错:javax.net.ssl.SSLHandshakeException: sun.security.validator.Val ...

  2. 【Spring】Feign客户端发送HTTPS请求绕过认证

    1.概述 转载:https://www.jianshu.com/p/ea627708ab52 一个Spring Boot项目,为了使用Harbor仓库,起初通过Spring RestTemplate完 ...

  3. JS(HTTP页面)发送HTTPS请求、同源策略

    今天遇到一个必须在前端HTTP页面发送HTTPS请求的功能,有点小尴尬,这个跨域问题,也没啥好的解决方式,我网上查了一下,也没啥好的方式! 后来总结了一下,有两种方式: 1.a标签 <a hre ...

  4. js发送https请求问题处理总结

    问题1 1.浏览器端无法发送https请求的时候 使用nginx进行转发,具体配置比较简单 问题2: 构建表单传送数据,提示缺失必要的参数. { "error" : "i ...

  5. VS2015编译Poco+openssl,使用Poco发送HTTPS请求

    下载源码.安装Openssl 下载Poco源码 git clone https://github.com/pocoproject/poco.git openssl下载安装: 下载地址:http://s ...

  6. restTemplate发送put请求

    restTemplate发送put请求 1.没有返回体 2.有返回体 HttpHeaders headers = new HttpHeaders(); headers.setContentType(o ...

  7. C程序|实现使用OPENSSL库 发送HTTPS请求,并接收数据|例如请求12306获取高铁、动车、火车车次信息的方法

    C程序|实现使用OPENSSL库 发送HTTPS请求,并接收数据|例如请求12306获取高铁.动车.火车车次信息的方法 1 HTTPS请求 1.1 研究浏览器发送的请求数据 1.2 代码实现 2 分析 ...

  8. HttpClient发送Https请求报 : unable to find valid certification path to requested target

    一.场景   近期在对接第三方接口时,通过HttpClient发送Https请求报 : unable to find valid certification path to requested tar ...

  9. Python urllib3和requests发送HTTPS请求时出现SSLError或InsecureRequestWarning

    目录 问题及原因分析 优先考虑的解决方法: 下载证书 使用证书 手动获取证书 不推荐使用的备用解决方法: 关闭方法 衍生问题 参考文档 问题及原因分析 在我们通过urllib3和requests进行H ...

最新文章

  1. T-SQL问题解决集锦——数据加解密
  2. 【机器学习基础】数学推导+纯Python实现机器学习算法19:PCA降维
  3. 马蜂窝数据仓库设计与实践
  4. ML.NET生成器带来了许多错误修复和增强功能以及新功能
  5. spring 动态代理_分析动态代理给 Spring 事务埋下的坑
  6. 不要惊奇这种观点400电话
  7. OpenCV获取图像的高和宽(Iplimage)
  8. python+selenium小米商城红米K40手机抢购!
  9. 如何打开.yml文件
  10. m3u8解析php,PHP解码转发M3U8 PHP读取转发M3U8的方法
  11. Excel如何生成11位随机数,包含大小写字母和数字
  12. SSM项目使用ConfigTools对数据库的密码进行加密
  13. W ndoWs7更新怎么关闭,怎么设置关闭win7自动更新
  14. allgro显示网络名称_ALLEGRO如何显示网络标号?
  15. 金山云CDN:国内最佳付费CDN
  16. CF417D--- Cunning Gena(序列+像缩进dp)
  17. 将小写字母转换成大写字母C/C++(指针)
  18. 这些专业配音软件你值得拥有
  19. Linux设置sudo无需密码【Ubuntu、多种方法】
  20. AngularJS中的谷歌地图开发

热门文章

  1. Halcon例程(基于3D形状匹配识别方法)详解 —— create_shape_model_3d_lowest_model_level.hdev
  2. halcon/c++接口基础 之 halcon初认识
  3. 第5章 Python 数字图像处理(DIP) - 图像复原与重建11 - 空间滤波 - 自适应滤波器 - 自适应局部降噪、自适应中值滤波器
  4. MNIST 手写数字识别,我是如何做到886个可训练参数,识别率达到98.2%? (参数、模型压缩), Keras实现,模型优化
  5. linux sed删除指定行_shell三剑客之sed!
  6. 基于C API的SQLite3基本数据库操作
  7. Visual C++2010的使用
  8. 实现 laravel 的artisan
  9. Vue提供操作DOM的方法
  10. Java动态代理深入解析