URL Decoder 异常 Illegal hex characters in escape (%)

在解析URL的时候,由于字符串中存在 % 导致解析失败

字符串 : http://passport.233.com/m/login/?redirectURL=https://m.233.com/chuji/shiti/202009/2114385550345.html?back=https://m.baidu.com/s?word=某公司2019年度企业所得税应纳税所得额¥10,000,000当年购置并实际使用液态符合节能节水专用设备企业所得税优惠目录规定的节能节水专用设备给专用设备通知我¥5,100,000已知企业所得税率25%计算该公司2019年一录音九那企业所得税额&from=1025096a

解析失败的异常: Caused by: java.lang.IllegalArgumentException: URLDecoder: Illegal hex characters in escape (%) pattern - For input string: “计算”

原因是: URL只能使用英文字母、阿拉伯数字和某些标点符号,不能使用其他文字和符号。如果内容中存在中文,必须要进行编解码。比如 “10%是黄段子” 转码过后是 “10%25%E6%98%AF%E9%BB%84%E6%AE%B5%E5%AD%90%” 被用来作为转义字符使用。

解决: 一个解决办法就是将%替换为%25。

Author: Tunan
Link: http://yerias.github.io/2021/09/05/error/12/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.