Documentation says I should use UTF-8 with URLEncoder.
I tried UTF-8. I got "cannot resolve symbol" error
URLEncoder.encode(str, "UTF_8");
I also tried this, but the API level is higher than I want it (level 19).
String UTF_8 = java.nio.charset.StandardCharsets.UTF_8.toString();
What is the proper and simple way to use this method with UTF-8?
The proper way is to spell it right. Try URLEncoder.encode(str, "UTF-8");
not with an underscore.
URLEncoder
This class is used to encode a string using the format required by application/x-www-form-urlencoded MIME content type.
All characters except letters ('a'..'z', 'A'..'Z') and numbers ('0'..'9') and characters '.', '-', '*', '_' are converted into their hexadecimal value prepended by '%'. For example: '#' -> %23. In addition, spaces are substituted by '+'.
The recommended encoding scheme to use is UTF-8
.
Use
URLEncoder.encode(str, "UTF-8");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With