from what I understand, UriComponentsBuilder
doesn't encode the query parameters automatically, just the original HttpUrl
it's instantiated with. In other words, you still have to explicitly encode:
UriComponentsBuilder is encoding your URI in accordance with RFC 3986 (see http://www.ietf.org/rfc/rfc3986.txt, in particular section 3.4 which is about the 'query' component of a URI).
Within the query
component, the characters '/' and ':'
are permitted, and do not need escaping.
To take the '/'
character for example: the query
component (which is clearly delimited by unescaped '?'
and (optionally) '#'
characters), is not hierarchical and the '/'
character has no special meaning. So it doesn't need encoding.
UriComponentsBuilder.fromUriString("/test/").queryParam("rt",URLEncoder.encode("http://a.com?u=1", "UTF-8")).build(false).encode().toUriString();
output : /test/?rt=http%253A%252F%252Fa.com%253Fu%253D1