I am sending sensitive data encrypted when the user clicks the onclick event. This encrypted data at times contains a plus sign (+
) When I retrieve this request variable on the server, the +
is getting converted to a whitespace. This causes the decr开发者_如何学运维yption to fail.
Example:
xrUxHtYpO2Yu3Z31ve+KNA==
gets converted to:
xrUxHtYpO2Yu3Z31ve KNA==
Is there a way escape the string so it is sent as is?
The function you're looking for is "encodeURIComponent()":
var encoded = encodeURIComponent("nasty string");
You shouldn't need any code at all on the server side; URL encoding will almost certainly be implicitly un-done by your web framework. (Edit - ah, if you're using some Java/JSP web framework, then you definitely don't have to do anything fancy on the server side.)
Try replacing the +
with %2B
. That came from HTML URL Encoding Reference at W3Schools. Hope this helps!
精彩评论