java 使用WebClient发送https请求

核心逻辑

绕过ssl证书检查

具体操作

话不多说上代码

javascript 复制代码
// 构建WebClient
public static WebClient createWebClient() throws SSLException {
    SslContext context = SslContextBuilder.forClient().trustManager(InsecureTrustManagerFactory.INSTANCE).build();
    HttpClient httpClient = HttpClient.create().secure(t -> t.sslContext(context));
    return WebClient.builder().clientConnector(new ReactorClientHttpConnector(httpClient)).build();

相关import

javascript 复制代码
import io.netty.handler.ssl.SslContext;
import io.netty.handler.ssl.SslContextBuilder;
import io.netty.handler.ssl.util.InsecureTrustManagerFactory;
import org.springframework.http.MediaType;
import org.springframework.http.client.reactive.ReactorClientHttpConnector;
import org.springframework.web.reactive.function.BodyInserters;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.netty.http.client.HttpClient;
import javax.net.ssl.SSLException;

具体使用

使用createWebClient()方法来构建WebClient进行SDK调用即可。

WebClient webClient = xxxx.createWebClient();

webClient.post()...

webClient.get()...

相关推荐
CodeByV9 分钟前
【C++】继承
开发语言·c++
青云交34 分钟前
Java 大视界 -- 基于 Java 的大数据可视化在城市空气质量监测与污染溯源中的应用
java·spark·lstm·可视化·java 大数据·空气质量监测·污染溯源
权泽谦39 分钟前
用 Python 做一个天气预报桌面小程序(附源码 + 打包与部署指导)
开发语言·python·小程序
ftpeak42 分钟前
《Rust+Slint:跨平台GUI应用》第八章 窗体
开发语言·ui·rust·slint
森语林溪1 小时前
大数据环境搭建从零开始(十七):JDK 17 安装与配置完整指南
java·大数据·开发语言·centos·vmware·软件需求·虚拟机
lsx2024061 小时前
HTML 音频(Audio)详解
开发语言
woshihonghonga1 小时前
【动手学深度学习】
开发语言·python
郝开1 小时前
Spring Boot 2.7.18(最终 2.x 系列版本)1 - 技术选型:连接池技术选型对比;接口文档技术选型对比
java·spring boot·spring
威风的虫2 小时前
ES6 数组方法:告别循环,拥抱函数式编程
开发语言·前端·javascript
码界筑梦坊2 小时前
240-基于Python的医疗疾病数据可视化分析系统
开发语言·python·信息可视化·数据分析·毕业设计·echarts