http URLEncoder

URLEncoder should be the way to go. You only need to keep in mind to encode only the query string parameter name and/or value, not the entire URL, even not the query string separator characters.Note that spaces in query parameters are represented by +, not %20, which is legitimately valid. The %20 is usually to be used to represent spaces in URI itself (the part before ?), not in query string (the part after ?).