想请教大家中文 URL 的编码问题
資深大佬 : magic961102 3
如题,短链接项目,传入的可能为中文,redirect 后中文变’?’,URLEncoder.encode 不能对整个链接编码,不然会出现“过度编码”的问题,有什么好的解决方案吗?
大佬有話說 (10)
如题,短链接项目,传入的可能为中文,redirect 后中文变’?’,URLEncoder.encode 不能对整个链接编码,不然会出现“过度编码”的问题,有什么好的解决方案吗?
public static void main(String[] args) throws Exception {
String urlStr = “http://test.com?q=真不戳”;
UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(urlStr);
String uriString = builder.toUriString();
System.out.println(uriString);
String decodeUriString = URLDecoder.decode(uriString, StandardCharsets.UTF_8.name());
System.out.println(decodeUriString);
}