1

I have a String that contains for example:

Hello are you ok ? 

I want to convert this String to:

Hello%20are%20you%20ok%20?

What do we call that and how can I do it in Java? Cause when I send a HttpRequest, the server doesn't understand the words without these special characters...

Russia Must Remove Putin
  • 374,368
  • 89
  • 403
  • 331
Fg.Salim
  • 49
  • 7

1 Answers1

2

What you want to use is URLEncoder :

String encodedUrl = URLEncoder.encode(url, "UTF-8");

Viktor K.
  • 2,670
  • 2
  • 19
  • 30
  • If `url` is `http://www.google.com/`, the encoded form is `http%3A%2F%2Fwww.google.com%2F` (a mess). The duplicate Q&A answers this much better. – Andrew Thompson Mar 09 '14 at 01:02