ENCODEURL$: Difference between revisions

From QB64 Phoenix Edition Wiki
Jump to navigation Jump to search
(Created page with "{{DISPLAYTITLE:_ENCODEURL$}} The '''_ENCODEURL$''' function returns the so called percent encoded representation of the given URL. {{PageSyntax}} : result$ = _ENCODEURL$({{Parameter|url$}}) {{PageParameters}} * {{Parameter|url$}} is the URL to encode as variable or literal STRING. {{PageDescription}} * URL encoding may be required before trying to retrieve it using the _OPENCLIENT("HTTP:url") command. * Proper encoding is under the obligatio...")
 
No edit summary
Line 19: Line 19:
** Chars & = (not encoded as query key separator respectively query value assignment on a simple 1:1 swap base).
** Chars & = (not encoded as query key separator respectively query value assignment on a simple 1:1 swap base).
** Control chars, spaces and extended ASCII (>127) are always encoded, regardless in which part of the URL they are used.
** Control chars, spaces and extended ASCII (>127) are always encoded, regardless in which part of the URL they are used.
** If the application uses unconventional URL notation, e.g. query parts like ''?foo=bar&baz&flip=true'' where the use of ampersands (&) is ambigous, then it must implement its own custom encoding routine, as only the application knows the correct syntax in such cases.
** If the application uses unconventional URL notation, e.g. query parts like ''?foo=bar&baz&flip=true'' where the use of ampersands (&) or other reserved chars is ambigous, then it must implement its own custom encoding routine, as only the application knows the correct syntax in such cases.
* Note that this function performs no validation of the given URL, it expects a valid URL to be given and just does the encoding.
* Note that this function performs no validation of the given URL, it expects a valid URL to be given and just does the encoding.
* Note also that it does not check, if the URL is already encoded. Although multiple times encoded URLs should not be a problem for most servers, it's recommended to avoid it.
* Note also that it does not check, if the URL is already encoded. Although multiple times encoded URLs should not be a problem for most servers, it's recommended to avoid it.

Revision as of 10:35, 26 November 2024

The _ENCODEURL$ function returns the so called percent encoded representation of the given URL.


Syntax

result$ = _ENCODEURL$(url$)


Parameters

  • url$ is the URL to encode as variable or literal STRING.


Description

  • URL encoding may be required before trying to retrieve it using the _OPENCLIENT("HTTP:url") command.
  • Proper encoding is under the obligation of the application, because only that knows how the URL currently looks like and hence if encoding is required or not.
  • This function performs the most simple encoding according to the informations found here, which is sufficient for the most work cases.
    • Chars - . _ ~ 0 to 9 Aa to Zz (not encoded).
    • Chars # / : ? @ [ ] (not encoded in address part but encoded in query part, first ? is not encoded and starts the query part).
    • Chars & = (not encoded as query key separator respectively query value assignment on a simple 1:1 swap base).
    • Control chars, spaces and extended ASCII (>127) are always encoded, regardless in which part of the URL they are used.
    • If the application uses unconventional URL notation, e.g. query parts like ?foo=bar&baz&flip=true where the use of ampersands (&) or other reserved chars is ambigous, then it must implement its own custom encoding routine, as only the application knows the correct syntax in such cases.
  • Note that this function performs no validation of the given URL, it expects a valid URL to be given and just does the encoding.
  • Note also that it does not check, if the URL is already encoded. Although multiple times encoded URLs should not be a problem for most servers, it's recommended to avoid it.


Availability


See also



Navigation:
Main Page with Articles and Tutorials
Keyword Reference - Alphabetical
Keyword Reference - By usage
Report a broken link