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

相关推荐
daidaidaiyu1 分钟前
Spring IOC 源码学习 事务相关的 BeanDefinition 解析过程 (XML)
java·spring
波波00731 分钟前
每日一题:.NET 中的“反射”是什么?
开发语言·.net
鬼蛟1 小时前
Spring————事务
android·java·spring
qq_461489331 小时前
C++与Qt图形开发
开发语言·c++·算法
Evand J1 小时前
【三维飞行器】RRT路径规划与TOA定位仿真系统,MATLAB例程,路径起终点、障碍物、TOA锚点等均可设置。附下载链接
开发语言·matlab·无人机·定位·rrt·toa·三维航迹规划
froginwe111 小时前
Rust 异步编程
开发语言
zayzy1 小时前
前端八股总结
开发语言·前端·javascript
今天减肥吗1 小时前
前端面试题
开发语言·前端·javascript
西门吹-禅2 小时前
【sap fiori cds up error】
java·服务器·sap cap cds
码码哈哈0.02 小时前
LangChain 快速入门(从0到可用)
开发语言·python·langchain