URLEncode (Socket function): Difference between revisions
m (1 revision) |
mNo edit summary |
||
(6 intermediate revisions by 2 users not shown) | |||
Line 5: | Line 5: | ||
The <var>URLEncode</var> function has an effect similar to | The <var>URLEncode</var> function has an effect similar to | ||
its equivalent $function, <var>[[$ | its equivalent $function, <var>[[$Sock_URL_Encode]]</var>. | ||
==Syntax== | ==Syntax== | ||
Line 12: | Line 12: | ||
===Syntax terms=== | ===Syntax terms=== | ||
<table class="syntaxTable"> | <table class="syntaxTable"> | ||
<tr><th>% | <tr><th>%string | ||
</th><td><var>Longstring</var> that is to contain the modified, encoded version of the input string <var class="term">string</var>. | </th><td><var>Longstring</var> that is to contain the modified, encoded version of the input string <var class="term">string</var>. | ||
</td></tr> | </td></tr> | ||
Line 24: | Line 24: | ||
==Usage notes== | ==Usage notes== | ||
<ul> | <ul> | ||
<li>The <var>Socket</var> method object (<var class="term"> | <li>The <var>Socket</var> method object (<var class="term">socket</var>) has associated with it | ||
the translation table used for the encoding of the special characters (see <var>[[XTAB]]</var>). | the translation table used for the encoding of the special characters (see <var>[[XTAB]]</var>). | ||
This translation table is necessary because special characters are converted | This translation table is necessary because special characters are converted | ||
Line 41: | Line 41: | ||
</ul> | </ul> | ||
== | ==Examples== | ||
In this example, <var>URLEncode</var> creates <code>%-hex-hex</code> encoding | In this example, <var>URLEncode</var> creates <code>%-hex-hex</code> encoding | ||
for this browser request to an HTTP server in the HTTP Get format: | for this browser request to an HTTP server in the HTTP Get format: | ||
<p class="code"> ... | <p class="code">... | ||
%rc = %sock:Send('GET /') | %rc = %sock:Send('GET /') | ||
%rc = %sock:Send(%url) | %rc = %sock:Send(%url) | ||
Line 51: | Line 50: | ||
%rc = %sock:Send(%sock:URLEncode(%info)) | %rc = %sock:Send(%sock:URLEncode(%info)) | ||
%rc = %sock:SendWithLineEnd(' HTTP/1.0') | %rc = %sock:SendWithLineEnd(' HTTP/1.0') | ||
... | |||
</p> | </p> | ||
For example, if <code>%info</code> contains: | For example, if <code>%info</code> contains: | ||
Line 63: | Line 62: | ||
slash (<tt>/</tt>). | slash (<tt>/</tt>). | ||
== | ==See also== | ||
{{Template:Socket:URLEncode footer}} | {{Template:Socket:URLEncode footer}} |
Latest revision as of 18:06, 30 October 2014
Use escape sequences to encode special chars (Socket class)
This method uses the URL "% hex hex" escape format to
encode the special characters in the string you specify.
The URLEncode function has an effect similar to its equivalent $function, $Sock_URL_Encode.
Syntax
%string = socket:URLEncode( string)
Syntax terms
%string | Longstring that is to contain the modified, encoded version of the input string string. |
---|---|
socket | A variable or an expression that is a reference to a Socket object. |
string | The string whose reserved characters are to be encoded using the "% hex hex" format. If this string is omitted, a null string is returned. |
Usage notes
- The Socket method object (socket) has associated with it the translation table used for the encoding of the special characters (see XTAB). This translation table 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. 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 URLEncode via the Socket object.
- URLEncode is particularly useful for constructing URLs, especially
when composing the query string portion of a URL (
http://host/path?query
). URLEncode is also useful for composing form data for a post request over an HTTP connection. - The non-alphanumeric characters that $Sock_Url_Encode does not encode are these seven:
. ( ) ! $ * - _
Examples
In this example, URLEncode creates %-hex-hex
encoding
for this browser request to an HTTP server in the HTTP Get format:
... %rc = %sock:Send('GET /') %rc = %sock:Send(%url) %rc = %sock:Send('?info=') %rc = %sock:Send(%sock:URLEncode(%info)) %rc = %sock:SendWithLineEnd(' HTTP/1.0') ...
For example, if %info
contains:
10 + 3.14 * R*R*R * 2/3
The following value is sent to the web server after the info=
:
10+%2B+3.14+*+R*R*R+*+2%2F3
+
signifies a blank, %
introduces a hex encoding,
2B
is the ASCII code for a plus sign (+), and 2f
is the ASCII code for a
slash (/).