URLDecoder is converting '+' into space

Nighthacks picture Nighthacks · Apr 12, 2017 · Viewed 7.5k times · Source

I have a hash key in one of my query params which can have + char with other special chars. The issue is when this URL is getting decoded URLDecoder converts + char into space. Is there a way we can enforce URLDecoder not to convert '+' into space.

Answer

mehulmpt picture mehulmpt · Apr 12, 2017

Do this on your string before decoding:

String plusEncoded = yourString.replaceAll("\\+", "%2b")

The decoder will then show + where it should've been