我必须将 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
最佳答案
先解码再编码
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");
关于java - 字符串 url 编码两次,我无法获取初始字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48715235/