RestTemplate 发送 Https 请求调用
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 请求调用相关推荐
- springboot 使用restTemplate 发送https请求 忽略ssl证书
最近在写接口的时候给对方回推数据,发送https请求的时候遇到这么个报错:javax.net.ssl.SSLHandshakeException: sun.security.validator.Val ...
- 【Spring】Feign客户端发送HTTPS请求绕过认证
1.概述 转载:https://www.jianshu.com/p/ea627708ab52 一个Spring Boot项目,为了使用Harbor仓库,起初通过Spring RestTemplate完 ...
- JS(HTTP页面)发送HTTPS请求、同源策略
今天遇到一个必须在前端HTTP页面发送HTTPS请求的功能,有点小尴尬,这个跨域问题,也没啥好的解决方式,我网上查了一下,也没啥好的方式! 后来总结了一下,有两种方式: 1.a标签 <a hre ...
- js发送https请求问题处理总结
问题1 1.浏览器端无法发送https请求的时候 使用nginx进行转发,具体配置比较简单 问题2: 构建表单传送数据,提示缺失必要的参数. { "error" : "i ...
- VS2015编译Poco+openssl,使用Poco发送HTTPS请求
下载源码.安装Openssl 下载Poco源码 git clone https://github.com/pocoproject/poco.git openssl下载安装: 下载地址:http://s ...
- restTemplate发送put请求
restTemplate发送put请求 1.没有返回体 2.有返回体 HttpHeaders headers = new HttpHeaders(); headers.setContentType(o ...
- C程序|实现使用OPENSSL库 发送HTTPS请求,并接收数据|例如请求12306获取高铁、动车、火车车次信息的方法
C程序|实现使用OPENSSL库 发送HTTPS请求,并接收数据|例如请求12306获取高铁.动车.火车车次信息的方法 1 HTTPS请求 1.1 研究浏览器发送的请求数据 1.2 代码实现 2 分析 ...
- HttpClient发送Https请求报 : unable to find valid certification path to requested target
一.场景 近期在对接第三方接口时,通过HttpClient发送Https请求报 : unable to find valid certification path to requested tar ...
- Python urllib3和requests发送HTTPS请求时出现SSLError或InsecureRequestWarning
目录 问题及原因分析 优先考虑的解决方法: 下载证书 使用证书 手动获取证书 不推荐使用的备用解决方法: 关闭方法 衍生问题 参考文档 问题及原因分析 在我们通过urllib3和requests进行H ...
最新文章
- T-SQL问题解决集锦——数据加解密
- 【机器学习基础】数学推导+纯Python实现机器学习算法19:PCA降维
- 马蜂窝数据仓库设计与实践
- ML.NET生成器带来了许多错误修复和增强功能以及新功能
- spring 动态代理_分析动态代理给 Spring 事务埋下的坑
- 不要惊奇这种观点400电话
- OpenCV获取图像的高和宽(Iplimage)
- python+selenium小米商城红米K40手机抢购!
- 如何打开.yml文件
- m3u8解析php,PHP解码转发M3U8 PHP读取转发M3U8的方法
- Excel如何生成11位随机数,包含大小写字母和数字
- SSM项目使用ConfigTools对数据库的密码进行加密
- W ndoWs7更新怎么关闭,怎么设置关闭win7自动更新
- allgro显示网络名称_ALLEGRO如何显示网络标号?
- 金山云CDN:国内最佳付费CDN
- CF417D--- Cunning Gena(序列+像缩进dp)
- 将小写字母转换成大写字母C/C++(指针)
- 这些专业配音软件你值得拥有
- Linux设置sudo无需密码【Ubuntu、多种方法】
- AngularJS中的谷歌地图开发
热门文章
- Halcon例程(基于3D形状匹配识别方法)详解 —— create_shape_model_3d_lowest_model_level.hdev
- halcon/c++接口基础 之 halcon初认识
- 第5章 Python 数字图像处理(DIP) - 图像复原与重建11 - 空间滤波 - 自适应滤波器 - 自适应局部降噪、自适应中值滤波器
- MNIST 手写数字识别,我是如何做到886个可训练参数,识别率达到98.2%? (参数、模型压缩), Keras实现,模型优化
- linux sed删除指定行_shell三剑客之sed!
- 基于C API的SQLite3基本数据库操作
- Visual C++2010的使用
- 实现 laravel 的artisan
- Vue提供操作DOM的方法
- Java动态代理深入解析