urlEncodeComponent

To avoid unexpected requests to the server, you should call encodeURIComponent on any user-entered parameters that will be passed as part of a URI. For example, a user could type "Thyme &time=again" for a variable comment. Not using encodeURIComponent on this variable will give comment=Thyme%20&time=again. Note that the ampersand and the equal sign mark a new key and value pair. So instead of having a POST comment key equal to "Thyme &time=again", you have two POST keys, one equal to "Thyme " and another (time) equal to again.

如果用户输入的部分要作为请求url, 这时用户可能会输入单双引号和空格或者&, 这也许并不是输入用户的本意,于是我们就要把字符转码, 试图还原输入的本意。

posted @ 2018-03-19 09:43  qqisnow2021  阅读(511)  评论(0编辑  收藏  举报