Pass a parameter containing '%' in URL?

后端 未结 2 1794
温柔的废话
温柔的废话 2020-12-10 09:48

While passing my url, for example something:8000/something.jsp?param1=update¶m2=1000¶m3=SearchString%¶m4=3 , I am getting following erro

相关标签:
2条回答
  • 2020-12-10 10:28

    Use %25 in place of % In URLs % has a special meaning as an escape character

    Special characters like (space) can be encoded like %20 (the ascii code for space/32 in hex)

    Therefore a percent sign itself must be encoded using the hex code for % which happens to be 25

    You can use http://www.asciitable.com/ to look up the appropriate hex code under the hx column

    Alternatively, if you are doing this programatically (ie. with javascript) you can use the builtin function escape() like escape('%')

    0 讨论(0)
  • 2020-12-10 10:36

    See this: Encode URL in JavaScript?

    Basically you need to make sure the variables you are passing are encoded (the '%' character is a special character in URL encoding).

    Any special characters - %,?,&, etc... need to be encoded. They are encoded with '%' and their hex number. So '%' should become '%25', '&' becomes '%26', etc.

    Update: see When are you supposed to use escape instead of encodeURI / encodeURIComponent? for why you should avoid using escape.

    0 讨论(0)
提交回复
热议问题