I'm trying to POST a request with application/x-www-form-urlencoded encoding but my WebClient keeps encoding my strings causing 400 Bad Requests from the server. I tried using a BuilderFactory with NONE encoding but with no luck, this is my code:
DefaultUriBuilderFactory factory = new DefaultUriBuilderFactory();
factory.setEncodingMode(DefaultUriBuilderFactory.EncodingMode.NONE);
WebClient webClient = WebClient.builder()
.defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
.defaultHeader(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE)
.defaultHeader(HttpHeaders.USER_AGENT, "WebClient/1")
.uriBuilderFactory(factory)
.build();
MultiValueMap<String, String> valueMap = new LinkedMultiValueMap<>();
valueMap.add("client_id", googleClientId);
valueMap.add("client_secret", googleClientSecret);
valueMap.add("refresh_token", "1//0ga...");
valueMap.add("grant_type", "refresh_token");
webClient.post()
.uri("https://some.free.beeceptor.com")
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
.body(BodyInserters.fromFormData(valueMap))
.retrieve()
.bodyToMono(RefreshTokenResponse.class)
.timeout(REQUEST_TIMEOUT_DURATION)
.block();
In the request above the refresh_token keeps being encoded as 1%2F%2F0ga, what can I do?