Spring 5 WebClient使用SSL

编程入门 行业动态 更新时间:2024-10-24 16:23:27
本文介绍了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

本文发布于:2023-11-05 09:28:50,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1560468.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Spring   WebClient   SSL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!