Looking at the implementation differences, I see that:
[-a-zA-Z0-9._*~'()!]
Java 1.5.0 documentation on URLEncoder
:
[-a-zA-Z0-9._*]
" "
is converted into a plus sign "+"
. So basically, to get the desired result, use URLEncoder.encode(s, "UTF-8")
and then do some post-processing:
"+"
with "%20"
"%xx"
representing any of [~'()!]
back to their literal counter-parts