2

I am having a problem with WebClient when setting the queryparams. This is the code:

WebClient webClient = WebClient.create(config.getOAuth2Url());

        return webClient.post()
                .uri(uriBuilder -> uriBuilder
                        .path("/oauth/authorize")
                        .queryParam(RESPONSE_TYPE, request.getResponse_type())
                        .queryParam(CLIENT_ID, request.getClient_id())
                        .queryParam(REDIRECT_URI, request.getRedirect_uri()) // pay attention here
                        .build())
                .header("cookie", jSessionId)
                .acceptCharset(StandardCharsets.UTF_8)
                .retrieve()
                .toEntity(JsonNode.class)
                .block();

The thing is that

request.getRedirect_uri()

is a String with % characters, like this:

https%3A%2F%2Fbra...

And I am getting a 400 error because WebClient is changing in some step this String with:

https%253A%252F%252Fbra

Of course if I try a curl with my original value it works, and if I try the curl with the modified string I get a 400. How can I change WebClient behavior so it doesn't modify my url?

  • So you are passing an already quoted value to a method that takes a parameter that isn't quoted? (Which `WebClient` - spring, apache, something else?) – Mr R Mar 11 '21 at 22:46
  • I am passing a string which contains the % character ("https%3A%2F%5D....findestring") and every %NUMBER is being modified to %25NUMBER as I showed above. – Guillermo Siles Bonilla Mar 11 '21 at 23:06
  • As for which webclient, I am using spring -> https://search.maven.org/classic/#search%7Cga%7C1%7Ca%3A%22spring-boot-starter-webflux%22%20AND%20g%3A%22org.springframework.boot%22 – Guillermo Siles Bonilla Mar 11 '21 at 23:06
  • Yes - so you are supplying something already pre-quoted to `queryParam()` - but according to examples out there you need the unquoted value. Maybe there's an alternate method which allows you to indicate its "already quoted" - otherwise need the unquoted value. – Mr R Mar 12 '21 at 00:06
  • Think about it - if it didn't quote things and one of your methods returned a value with & or ? or # in it what would it do to the URI that was built? – Mr R Mar 12 '21 at 00:07
  • Check out the answer for this question - which goes into alot of depth explaining what needs quoting and what doesn't ... AND [URIBuilder](https://javaee.github.io/javaee-spec/javadocs/javax/ws/rs/core/UriBuilder.html#queryParam-java.lang.String-java.lang.Object...-) explains that things get modified ... – Mr R Mar 12 '21 at 00:54
  • Ohhhh I understand now, you are absolutely right. I didn't realize this are quoted values, I am still quite a junior. If you want to write an answer I will mark it as the answer to this question. Thanks! – Guillermo Siles Bonilla Mar 12 '21 at 08:02

0 Answers0