What is URL Encoding?
When you pass information through a URL, you need to make sure it only uses specific allowed characters like: alphabetic characters, numerals, and a few special characters that have meaning in the URL string. Any other characters should be encoded so that they don't cause problems.
The most commonly encoded character is the <space> character. You see this character whenever you see a plus-sign (+) in a URL. This represents the space character. The plus sign acts as a special character representing a space in a URL. The most common way you'll see this is in a mailto link that includes a subject. If you want the subject to have spaces in it, you can encode them as pluses:
mailto:email?subject=this+is+my+subject
How Do You Encode a URL?
Simply replace the special characters with their encoding string. This will nearly always begin with a %. If you don't want to do it by hand, you can use a script such as is found on the JavaScript site: Encoding Web Addresses.
How URL_Decoding can be done in Message Broker?
I. When the HTTP client sends the Request-Type as “GET” and the Content-type as “URL-Encoded”,then our Message broker HTTPInput node by itself can decode the url-encoded input message .
To extract the decoded message ,we have to enable the “parseQueryString” property in the HTTPInput node as below.
Then the decoded message will be present in the below path.We can extract the message from this path for further use.
For eg:
SET Environment.Variables.OriginalMessage = CAST(InputLocalEnvironment.HTTP.Input.QueryString.Input AS BLOB CCSID 1208);
II. When the HTTP client sends the Request-Type as “POST” and the Content-type as “URL-Encoded”,then our Message broker HTTPInput node cannot by itself decode the url-encoded input message .
The following method can be used to achieve such scenarios.
Introduce a “Javacompute node” after HTTPInput node.
String result = java.net.URLDecoder.decode("=%3cn%3aMessage+xmlns%3an%3d%22http%3a%2f%2f%3e%5d%5d%3e%3c%2fMsg%3e%3c%2fn%3aMessage%3e", "UTF-8");
Refer the message in a variable or directly as shown in the above example.
No comments:
Post a Comment