Java Rest Web Service: '+' character inside String param is treated as space character -
my client app sends string servers side decode it. string in question may contain '+' characters. problem when want treat string, seams '+' chars gone (probably treated concatenation operators. how solve problem? string not right type that? should use byte[] instead?
client side:
$.ajax({ type: "get", url: "my/url/decryptstring", data: "encryptedstring="+$("#mystringinput").val(), ...
code on server side:
... public string decryptstring(@queryparam("encryptedstring") string encryptedstring) { logger.info("=====> decryptstring()"); string decryptedstring = null; properties properties = new properties(); logger.debug("encryptedstring: " + encryptedstring); // crypto properties try { properties.load(toto.class.getresourceasstream("/config.properties")); } catch (ioexception e1) { logger.error(e1.getstacktrace()); } if(properties.isempty()) { logger.error("properties file empty!"); } string encodekey = properties.getproperty("toto.crypt.encodekey"); decryptedstring = crypto.decrypt(encodekey, encryptedstring.tostring()); return decryptedstring; }
the string passed encrypted string on client side is: '7nfasg++qlosfdxbr8wzcw=='
here traces on server side:
debug encryptedstring: 7nfasg qlosfdxbr8wzcw==
+
in query params treated encodings spaces, that's why 7nfasg++qlosfdxbr8wzcw==
decoded 7nfasg qlosfdxbr8wzcw==
. if want transport +
through query param, encode %2b
(see request parameter losing plus sign).
Comments
Post a Comment