$Sock_URL_Encode

From m204wiki
Revision as of 00:00, 21 September 2018 by JALWiccan (talk | contribs) (Automatically generated page update)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Encode into URL "% hex hex" format

Note: Many $functions have been deprecated in favor of Object Oriented methods. The OO equivalent for $Sock_URL_Encode is the URLEncode method.

$Sock_URL_Encode encodes special characters into the URL "% hex hex" format, which has particular use constructing URLs, especially those containing query strings for HTTP connections. $Sock_URL_Encode is also useful for encoding form post data for HTTP connections.

Syntax

%longStr = $Sock_URL_Encode(string, sockNum)

Syntax terms

%longStr A Longstring to contain the encoding of the input string.
string The input string to be translated. If this string is omitted, a null string is returned.
sockNum The socket number, which has associated with it the translation table used for encoding special characters.

Usage notes

  • The translation table associated with the socket number is necessary because special characters are converted to the hexadecimal representations of their ASCII values, even though the input and output strings are both in EBCDIC. So any data that must be encoded as hexadecimal must be translated to ASCII first, which means that the appropriate ASCII-to-EBCDIC translation table must be indicated to $Sock_URL_Encode via the socket number.

Example

$Sock_URL_Encode is useful when composing the query string portion of a URL (HTTP://host/path?query), or when composing form data for a post request over HTTP:

* Use $Sock_URL_Encode to create % hex hex %r = $Sock_Send(%x, 'GET /') %r = $Sock_Send(%x, %URL) %r = $Sock_Send(%x, '?info=') %r = $Sock_Send(%x, $Sock_URL_Encode(%info)) %r = $Sock_SendLn(%x, ' HTTP/1.0')

For example, if %info contained:

10 + 3.14 * R*R*R * 2/3

The following value would be sent to the web server after the info=:

10+%2B+3.14+*+R*R*R+*+2%2F3

+ is used to stand for a blank, % introduces a hex encoding, 2B is the ASCII code for a plus sign (+), and 2F is the ASCII code for a slash (/).

The non-alphanumeric characters that $Sock_URL_Encode does not encode are:

. ( ) ! $ * - _