$Sock URL Encode: Difference between revisions

From m204wiki
Jump to navigation Jump to search
(Automatically generated page update)
mNo edit summary
Line 2: Line 2:
<span class="pageSubtitle">Encode into URL "% hex hex" format</span>
<span class="pageSubtitle">Encode into URL "% hex hex" format</span>
<p class="warn"><b>Note: </b>Most Sirius $functions have been deprecated in favor of Object Oriented
<p class="warn"><b>Note: </b>Most Sirius $functions have been deprecated in favor of Object Oriented
methods. There is currently no direct OO equivalent for this $function.</p>
methods. The OO equivalent for <var>$Sock_URL_Encode</var> is the <var>[[URLEncode (Socket function)|URLEncode]]</var> method.</p>


<var>$Sock_URL_Encode</var> encodes special characters into the URL "% hex hex"
<var>$Sock_URL_Encode</var> encodes special characters into the URL "% hex hex"

Revision as of 22:00, 23 July 2013

Encode into URL "% hex hex" format

Note: Most Sirius $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:

. ( ) ! $ * - _