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

相关推荐
薯条不要番茄酱4 分钟前
【JavaEE初阶】多线程重点知识以及常考的面试题-多线程进阶(三)
java·java-ee
doglc15 分钟前
从零手写RPC-version0
java·git·rpc·maven·intellij idea
捡田螺的小男孩24 分钟前
10万QPS高并发请求,如何防止重复下单
java·后端·面试
桃子叔叔31 分钟前
python学习从0到专家(8)容器之列表、元组、字典、集合、字符串小结
开发语言·python·学习
溟洵35 分钟前
【C++ Qt】Hello World、初始信号槽、理解对象树 ~~~(通俗易懂 图文并茂)
开发语言·c++·qt
m0_7269659837 分钟前
Java Bean演进历程:从POJO到Spring Boot配置绑定
java·开发语言·spring boot
SnXJi_40 分钟前
纷析云开源财务软件:助力企业财务管理数字化转型
java·gitee·开源·开源软件·gitcode
八股文领域大手子1 小时前
深入浅出 Redis:核心数据结构解析与应用场景Redis 数据结构
java·数据结构·数据库·人工智能·spring boot·redis·后端
尽兴-1 小时前
常用 Git 命令详解
java·git·vscode·gitee