WebFormUrlEncode Function

Action

Encodes any unsafe characters included in URLs in order to comply with the Uniform Resource Locators specification. This encoding is commonly applied to URL parameters or FORM post parameters.

Include file

WebAPI.bdh

Syntax

WebFormUrlEncode( out   sTarget    :string,
                  inout nMaxTarget : number,
                  in    sSource    : string ): boolean;

Return value

  • true if encoding was successful

  • false if an error occurred or the buffer size is too small

Parameter Description
sTarget String variable to receive the encoded string
nMaxTarget Parameter containing the maximum number of characters to write into sTarget. This value must be <=<= the size of sTarget. If the buffer size is too small, WebFormUrlEncode returns false and sets nMaxTarget to the needed size.
sSource Source string to encode

Printable ASCII characters being URL-encoded to its hexadecimal representation %hh by Silk Performer: % ? # [ ] { } | \ & = @ : ^ ~ ` " $ + ! * ' ( ) , < > ; /

Note: Octets must be encoded if they have no corresponding graphic character within the US ASCII coded character set, if the use of the corresponding character is unsafe, or if the corresponding character is reserved for some other interpretation within the particular URL scheme. No corresponding graphic US ASCII: URLs are written only with the printable graphic characters of the US ASCII coded character set. The octets 80-FF hexadecimal are not used in US ASCII, and the octets 00-1F and 7F hexadecimal represent control characters; these must be encoded.

Example

dcltrans
  transaction TWebFormUrlEncode
  var
    sUrl     : string;
    sPass    : string(100);
    nPassLen : number;
  begin
    // Encode all unsafe characters in a password
    nPassLen := sizeof(sPass);
    WebFormUrlEncode(sPass, nPassLen, "paranoia{}[]~^");
    sUrl := "http://smith:" + sPass + "@standardhost/";
    WebUrl(sUrl);
  end TWebFormUrlEncode;

Sample scripts

WebEncoding01.bdf