$Sock URL Encode: Difference between revisions
m (1 revision) |
(Automatically generated page update) |
||
(3 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
{{DISPLAYTITLE:$Sock_URL_Encode}} | {{DISPLAYTITLE:$Sock_URL_Encode}} | ||
<span class="pageSubtitle">Encode into URL "% hex hex" format</span> | <span class="pageSubtitle">Encode into URL "% hex hex" format</span> | ||
<p class=" | <p class="warn"><b>Note: </b>Many $functions have been deprecated in favor of Object Oriented | ||
methods. | 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" | ||
Line 10: | Line 10: | ||
==Syntax== | ==Syntax== | ||
<p class="syntax"><span class="term">% | <p class="syntax"><span class="term">%longStr</span><span class="literal"> = $Sock_URL_Encode(</span><span class="term">string</span><span class="literal">,</span> <span class="term">sockNum</span><span class="literal">)</span> </p> | ||
===Syntax terms=== | ===Syntax terms=== | ||
<table class="syntaxTable"> | <table class="syntaxTable"> | ||
<tr><th>% | <tr><th>%longStr</th> | ||
<td>A <var>Longstring</var> to contain the encoding of the input string. </td></tr> | <td>A <var>Longstring</var> to contain the encoding of the input string. </td></tr> | ||
<tr><th>string</th> | <tr><th>string</th> |
Latest revision as of 00:00, 21 September 2018
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:
. ( ) ! $ * - _