如何在java中解码x-www-form-urlencoded表单数据,该数据具有未转义的%作为数据

问题描述 投票:0回答:1

我遇到了一种情况,我收到 x-www-form-urlencoded 表单数据,我需要对其进行解码。

如何在 java 中解码 x-www-form-urlencoded 表单数据,该数据具有未转义的 % 作为数据。 例如“APL%205%%20off”实际上应解码为“APL 5% off” 然而,我尝试了一些java代码片段以及一些在线解码器,但都抛出异常或说无效。

我需要了解如何实现这一点?如果有人可以分享知识,将不胜感激。

java urldecode
1个回答
0
投票

你必须使用RegEx(正则表达式)

Pattern pattern = Pattern.compile("Text to be used in a search", Pattern.CASE_INSENSITIVE);
    Matcher matcher = pattern.matcher("Text Used to search for the pattern");
    boolean matchFound = matcher.find();
    if(matchFound) {
      System.out.println("Found");
    } else {
      System.out.println("Not found");
    }

这两个链接将帮助您进行正则表达式匹配

https://www.kompf.de/java/regex.html

https://regex101.com

© www.soinside.com 2019 - 2024. All rights reserved.