3

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);
Wesos de Queso
  • 1,526
  • 1
  • 21
  • 23

2 Answers2

5

You would use Java's URLEncoder As in URLEncoder.encode("Børomìr", "UTF-8");

toltman
  • 467
  • 2
  • 6
2

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

Tayyab Hussain
  • 107
  • 2
  • 10