Decoding URI query string in Java

后端 未结 5 464
离开以前
离开以前 2020-12-05 09:50

I need to decode a URI that contains a query string; expected input/output behavior is something like the following:

abstract class URIParser
{       
    /*         


        
5条回答
  •  一生所求
    2020-12-05 10:37

    Use

    URLDecoder.decode(proxyRequestParam.replace("+", "%2B"), "UTF-8")
              .replace("%2B", "+")
    

    to simulate decodeURIComponent. Java's URLDecoder decodes the plus sign to a space, which is not what you want, therefore you need the replace statements.

    Warning: the .replace("%2B", "+") at the end will corrupt your data if the original (pre-x-www-form-urlencoded) contained that string, as @xehpuk pointed out.

提交回复
热议问题