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

相关推荐
Dcs13 小时前
Java 中 UnaryOperator 接口与 Lambda 表达式的应用示例
java·后端
bagadesu15 小时前
使用Docker构建Node.js应用的详细指南
java·后端
没有bug.的程序员15 小时前
Spring Cloud Gateway 性能优化与限流设计
java·spring boot·spring·nacos·性能优化·gateway·springcloud
molunnnn15 小时前
第四章 Agent的几种经典范式
开发语言·python
洛_尘16 小时前
JAVA EE初阶 2: 多线程-初阶
java·开发语言
Slow菜鸟16 小时前
Java 开发环境安装指南(五) | Git 安装
java·git
@卞17 小时前
C语言常见概念
c语言·开发语言
wjs202417 小时前
Eclipse 关闭项目详解
开发语言
沐知全栈开发17 小时前
《隐藏(Hide)》
开发语言