In my application about World of Warcraft mythic dungeons i have to do some queries into the raiderio Public API. I having a big issue when the players name it's something like this :
https://raider.io/api/v1/characters/profile?region=US&realm=https://raider.io/characters/us/zuljin/Børomìr&name=&fields=mythic_plus_best_runs%3Aall
this name : Børomìr
In the API this query doesn't work because it manages special characters like this:
https://raider.io/api/v1/characters/profile?region=us&realm=zuljin&name=B%C3%B8rom%C3%ACr&fields=mythic_plus_best_runs%3Aall
becomes this : B%C3%B8rom%C3%ACr
where:
ø becomes %C3%B8
ì becomes %C3%AC
which tool do i need to generate this conversion in java?
Heres is the URL request code:
String body = "";
URL url = new URL("https://raider.io/api/v1/characters/profile?region="+region.toString()+"&realm="+realm+"&name="+name+"&fields=mythic_plus_best_runs%3Aall");
System.out.println(url.toString());
URLConnection uc = url.openConnection();
uc.addRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)");
InputStream in = uc.getInputStream();
String encoding = uc.getContentEncoding();
encoding = encoding == null ? "UTF-8"
// "windows-1251"
// "Cp1251"
: encoding;
body = IOUtils.toString(in, encoding);
You would use Java's URLEncoder As in URLEncoder.encode("Børomìr", "UTF-8");
This is what is called percent encoding and is what is used in URLs. There are many tools that allow you to decode it like this one. Specifically in java, it has a URL encoder
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