Neo
Neo

Reputation: 5228

How to disable the security certificate check in Java webflux webclient requests

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 ?

Upvotes: 4

Views: 17043

Answers (1)

Paul Croarkin
Paul Croarkin

Reputation: 14675

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

Upvotes: 17

Related Questions