在我关于《魔兽世界》史诗地下城的应用程序中,我必须查询raiderio公共API。当玩家的名称像这样时,我遇到了一个大问题:
在API中,这个查询无法工作,因为它会处理特殊字符,如下所示:
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
在API中,这个查询无法工作,因为它会处理特殊字符,如下所示:
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:
ø
变成%C3%B8
ì
变成%C3%AC
我需要哪个工具来在Java中生成这种转换?
以下是URL请求代码:
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);