Encoding URL query parameters in Java

John Doe ·

1180 Views

Q: How does one encode query parameters to go on a url in Java?

A: java.net.URLEncoder.encode(String s, String encoding) can help too. It follows the HTML form encoding application/x-www-form-urlencoded.

URLEncoder.encode(query, "UTF-8");

On the other hand, Percent-encoding (also known as URL encoding) encodes space with %20. Colon is a reserved character, so : will still remain a colon, after encoding.

ref. https://stackoverflow.com/questions/5330104/encoding-url-query-parameters-in-java

urlencode