how to use URL-encode in ABL

redsuitee

Member
I have a problem to use URL-encode function.
I want to encode a string to finish my query.
But I don't understand how to run the function.
I read the help, it mentions a location web\method\cgiutils.i
Actually I don't understand what is it means?
Anybody can explain me how to use URL-encode in ABL?
I highly appreciate for the help.
Thanks.
 

Marian EDU

Member
I want to encode a string to finish my query.

if that's for building a query sting of a dynamic query then you should look at `quoter` function, url-encode is mainly to escape restricted characters from URL address
 

redsuitee

Member
if that's for building a query sting of a dynamic query then you should look at `quoter` function, url-encode is mainly to escape restricted characters from URL address

here is my project -> http://docs.amazonwebservices.com/A...eveloperGuide/index.html?Query_QueryAuth.html
It's mentioned that "The final signature you send in the request must be URL encoded ... make sure to URL encode the signature before you include it in the request."
Is it right or not if I use the url-encode better than quoter?
Many thanks.
 

WinningJr

New Member
If I'm understanding your question, you are trying to use url-encode but you are not using the CGI wrapper template that puts in the includes that would allow you to use the "URL-Encode" function. If this is the case, you can pull the encode function from the includes and put it into your own function. I think I pulled this one from 10.2B:

FUNCTION url-encode-mine RETURNS CHARACTER
(INPUT p_value AS CHARACTER) :
/****************************************************************************
Description: Encodes unsafe characters in a URL as per RFC 1738 section 2.2.
<URL:http://ds.internic.net/rfc/rfc1738.txt>, 2.2
Input Parameters: Character string to encode, Encoding option where "query",
"cookie", "default" or any specified string of characters are valid.
In addition, all characters specified in the global variable url_unsafe
plus ASCII values 0 <= x <= 31 and 127 <= x <= 255 are considered unsafe.
Returns: Encoded string (unkown value is returned as blank)
Global Variables: url_unsafe, url_reserved
****************************************************************************/
DEFINE VARIABLE hx AS CHARACTER NO-UNDO INITIAL "0123456789ABCDEF":U.
DEFINE VARIABLE encode-list AS CHARACTER NO-UNDO INIT " <>~"#%~{}|~\^~~[]`~;/?:mad:=&".
DEFINE VARIABLE i AS INTEGER NO-UNDO.
DEFINE VARIABLE c AS INTEGER NO-UNDO.

/* Don't bother with blank or unknown */
IF LENGTH(p_value) = 0 OR p_value = ? THEN
RETURN "".

/* Loop through entire input string */
ASSIGN i = 0.
DO WHILE TRUE:
ASSIGN
i = i + 1
/* ASCII value of character using single byte codepage */
c = ASC(SUBSTRING(p_value, i, 1, "RAW":U), "1252":U, "1252":U).
IF c <= 31 OR c >= 127 OR INDEX(encode-list, CHR(c)) > 0 THEN DO:
/* Replace character with %hh hexidecimal triplet */
SUBSTRING(p_value, i, 1, "RAW":U) =
"%":U +
SUBSTRING(hx, INTEGER(TRUNCATE(c / 16, 0)) + 1, 1, "RAW":U) + /* high */
SUBSTRING(hx, c MODULO 16 + 1, 1, "RAW":U). /* low digit */
ASSIGN i = i + 2. /* skip over hex triplet just inserted */
END.
IF i = LENGTH(p_value,"RAW":U) THEN LEAVE.
END.
RETURN p_value.
END FUNCTION. /* url-encode */
 
Top