@Bean
public WebClient webClient() {
HttpClient httpClient = HttpClient.create()
.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 5000)
.responseTimeout(Duration.ofMillis(5000))
.doOnConnected(connection ->
connection.addHandlerLast(new ReadTimeoutHandler(5000, TimeUnit.MICROSECONDS))
.addHandlerLast(new WriteTimeoutHandler(5000, TimeUnit.MICROSECONDS)));
return WebClient.builder()
.clientConnector(new ReactorClientHttpConnector(httpClient))
.build();
}
참고: https://www.baeldung.com/spring-5-webclient
UriComponentsBuilder를 사용하면 된다. (Baeldung 참고)
UriComponentsBuilder builder = UriComponentsBuilder.fromUriString("https://nid.naver.com/oauth2.0/authorize")
.queryParam("response_type", RESPONSE_TYPE)
.queryParam("client_id", clientId)
.queryParam("redirect_uri", REDIRECT_URI);
String code = webClient.mutate()
.build()
.get()
.uri(builder.build().toUri())
.retrieve()
.bodyToMono(String.class)
.block();