我必须将URL编码为已经部分编码的字符串。当我对字符串进行编码时,它会对已编码的字符进行两次编码。解码后,我无法返回字符串,因为它已被编码两次。
是否只能编码未加密的字符?
urlEncoded = URLEncoder.encode(id, "UTF-8");
要编码的网址示例:
http://gastro-huc.org.pt/index.php?view=article&catid=41%3Ateses-de-mestrado&id=41%3Ateses-de-mestrado&format=pdf&option=com_content&Itemid=68
答案 0 :(得分:2)
String id = "http://gastro-huc.org.pt/index.php?view=article&catid=41%3Ateses-de-mestrado&id=41%3Ateses-de-mestrado&format=pdf&option=com_content&Itemid=68";
id = URLDecoder.decode(id);
String urlEncoded = URLEncoder.encode(id, "UTF-8");