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()...

相关推荐
zl9798996 分钟前
MybatisPlus-注解
java·spring·maven
thinkMoreAndDoMore14 分钟前
深度学习(3)-TensorFlow入门(常数张量和变量)
开发语言·人工智能·python
杰九16 分钟前
【环境配置】maven,mysql,node.js,vue的快速配置与上手
java·vue.js·spring boot·mysql·node.js·maven
wapicn9927 分钟前
‌挖数据平台对接DeepSeek推出一键云端部署功能:API接口驱动金融、汽车等行业智能化升级
java·人工智能·python·金融·汽车·php
蓝桉8021 小时前
图片爬取案例
开发语言·数据库·python
逸狼1 小时前
【JavaEE进阶】Spring DI
java·开发语言
yonuyeung1 小时前
代码随想录算法【Day54】
java·数据结构·算法
敲上瘾1 小时前
基础dp——动态规划
java·数据结构·c++·python·算法·线性回归·动态规划
my_styles1 小时前
2025-alibaba-Sentinel组件
java·开发语言·sentinel