UrlEncoder encodes spaces as + instead of %20, which is consistent with application/x-www-form-urlencoded and OK in query strings, but causes an error if it's in other components.
A solution would be to use java.net.URI to build the uri. I can write a PR if needed.