使用 ssl 的 Spring 5 WebClient [英] Spring 5 WebClient using ssl
本文介绍了使用 ssl 的 Spring 5 WebClient的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试查找 WebClient 使用示例.
I'm trying to find examples of WebClient use.
我的目标是使用 Spring 5 WebClient 通过 https 和自签名证书查询 REST 服务
My goal is to use Spring 5 WebClient to query a REST service using https and self signed certificate
有什么例子吗?
推荐答案
查看使用示例 不安全的 TrustManagerFactory 信任所有 X.509 证书(包括自签名)而无需任何验证.文档中的重要说明:
See example of use insecure TrustManagerFactory that trusts all X.509 certificates (including self-signed) without any verification. The important note from documentation:
切勿在生产中使用此 TrustManagerFactory.它纯粹是为了测试目的,因此非常不安全.
Never use this TrustManagerFactory in production. It is purely for testing purposes, and thus it is very insecure.
@Bean
public WebClient createWebClient() throws SSLException {
SslContext sslContext = SslContextBuilder
.forClient()
.trustManager(InsecureTrustManagerFactory.INSTANCE)
.build();
ClientHttpConnector httpConnector = HttpClient.create().secure(t -> t.sslContext(sslContext) )
return WebClient.builder().clientConnector(httpConnector).build();
}
这篇关于使用 ssl 的 Spring 5 WebClient的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文