gpt4 book ai didi

java - URL解码不改变+

转载 作者:行者123 更新时间:2023-12-01 15:24:27 27 4
gpt4 key购买 nike

我想解码 URL,但仅限于 % 编码。我想保持非 % 编码不变:

例如

url = 
http%3A%2F%2Fwww.domain.com%2FNews%2Fpolitics%2FMPs%2Brisk%2Blosing%2Bparliamentary%2Bimmunity%2B%2F-%2F1064%2F1395978%2F-%2Flvylki%2F-%2Findex.html

URLDecoder.decode(url, "UTF-8") = http://www.domain.com/News/politics/MPs+risk+losing+parliamentary+immunity+/-/1064/1395978/-/lvylki/-/index.html

但是如果:

url = http://www.domain.com/News/politics/MPs+risk+losing+parliamentary+immunity+/-/1064/1395978/-/lvylki/-/index.html

URLDecoder.decode(url, "UTF-8") = http://www.domain.com/News/politics/MPs risk losing parliamentary immunity /-/1064/1395978/-/lvylki/-/index.html

我想要:

URLDecoder.decode(url, "UTF-8") = http://www.domain.com/News/politics/MPs+risk+losing+parliamentary+immunity+/-/1064/1395978/-/lvylki/-/index.html

如何避免 URLDecoder.decode() 将 + 解码为“”。一般来说,我想保留非 % 编码的字符串完整,即仅转换 % 编码。

最佳答案

URLDecoder.decode(url.replaceAll("\\+", "%2B"))

关于java - URL解码不改变+,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10375409/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com