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

相关推荐
小七mod2 分钟前
【Spring】Java SPI机制及Spring Boot使用实例
java·spring boot·spring·spi·双亲委派
Tipriest_3 分钟前
Python异常类型介绍
开发语言·python·异常
Swift社区16 分钟前
Swift 解 LeetCode 321:拼接两个数组中的最大数,贪心 + 合并全解析
开发语言·leetcode·swift
亿.627 分钟前
【Java安全】RMI基础
java·安全·ctf·rmi
ruan11451442 分钟前
Java Lambda 类型推断详解:filter() 方法与 Predicate<? super T>
java·开发语言·spring·stream
朱杰jjj44 分钟前
解决jenkins的Exec command命令nohup java -jar不启动问题
java·jenkins·jar
广东数字化转型1 小时前
java jar 启动应用程序
开发语言·python
阿幸软件杂货间1 小时前
阿幸课堂随机点名
android·开发语言·javascript
小何学计算机1 小时前
HTTPS工作原理
网络协议·http·https
threelab1 小时前
three案例 Three.js波纹效果演示
开发语言·javascript·ecmascript