0

通过 webflux webclient 发出 post/get 请求时,如何禁用 ssl 检查?

我正在使用的示例构建器代码:

WebClient webClient = WebClient.builder()
        .baseUrl("https://api.github.com")
        .defaultHeader(HttpHeaders.CONTENT_TYPE, "application/vnd.github.v3+json")
        .defaultHeader(HttpHeaders.USER_AGENT, "Spring 5 WebClient")
        .build();

在上面的代码中,应该进行哪些更改以使 ssl 验证为 false ?

4

1 回答 1

2
        SslContext sslContext = SslContextBuilder
            .forClient()
            .trustManager(InsecureTrustManagerFactory.INSTANCE)
            .build();
    
        HttpClient httpClient = HttpClient.create().secure(t -> t.sslContext(sslContext));
    
        WebClient webClient = WebClient.builder()
            .baseUrl("https://api.github.com")
            .defaultHeader(HttpHeaders.CONTENT_TYPE, "application/vnd.github.v3+json")
            .defaultHeader(HttpHeaders.USER_AGENT, "Spring 5 WebClient")
            .clientConnector(new ReactorClientHttpConnector(httpClient))
            .build();
于 2021-08-03T18:06:46.910 回答