2

While making post/get requests through webflux webclient how can ssl check be disabled ?

Sample builder code which I'm using:

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

In above code what change should be made to make ssl verification false ?

Neo
  • 5,070
  • 10
  • 46
  • 65
  • Would you have the option to import the server certificate to your JVM's trust store? Disabling the cert check altogether sort of defeats the purpose of using TLS. – Mick Mnemonic Jul 12 '19 at 19:58
  • here you can find what you are looking for, and remember this is very, very bad practice. Just for info: https://stackoverflow.com/questions/45418523/spring-5-webclient-using-ssl – Toerktumlare Jul 12 '19 at 23:23

1 Answers1

13
        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();
Paul Croarkin
  • 14,496
  • 14
  • 79
  • 118