本文介绍了Spring 5 WebClient使用SSL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试查找WebClient使用的示例. 我的目标是使用Spring 5 WebClient通过https和自签名证书查询REST服务
I'm trying to find examples of WebClient use. 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(); }
更多推荐
Spring 5 WebClient使用SSL
发布评论