如题,短链接项目,传入的可能为中文,redirect 后中文变'?',URLEncoder.encode 不能对整个链接编码,不然会出现“过度编码”的问题,有什么好的解决方案吗?
如题,短链接项目,传入的可能为中文,redirect 后中文变'?',URLEncoder.encode 不能对整个链接编码,不然会出现“过度编码”的问题,有什么好的解决方案吗?
|
1
手动置顶
|
|
JinTianYi456Feb 4, 2021
2
是不是这个? /t/737430
|
|
3
@JinTianYi456 但是这个没有解决问题
|
|
4
或者有没有第三方的包能实现
|
|
luozicFeb 5, 2021
5
写一个去除部分符号的编码方式。
|
|
chendyFeb 5, 2021
6
SpringWeb 的 UriComponenetBuilder,不知道能不能满足需求:
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); } |
|
yksoft1testFeb 5, 2021
7
把域名和路径分开编码,域名用 punycode,路径先 UTF8 化再 URLEncode 。
|
|
8
@yksoft1test 分开比较麻烦,长链接传进来最好能完整处理
|
|
9
@chendy 我一会试试看
|
|
10
@luozic 看来自己写是最灵活的了
|