WebBase64Encode Function

Action

Converts unsigned binary input into ASCII-encoded, printable characters.

Note: This function is obsolete. It can still be used, although it's recommended to use the WebBase64EncodeEx function instead.

Include file

WebAPI.bdh

Syntax

WebBase64Encode( out sTarget    :string,
                 in  nMaxTarget : number,
                 out nLenTarget : number,
                 in  sSource    : string,
                 in  nSourceLen : number optional ): boolean;

Return value

  • true if the encoding was successful

  • false otherwise

Parameter Description
sTarget String variable to receive the encoded string.
nMaxTarget Maximum number of characters to write into sTarget.
nLenTarget Parameter receiving the number of characters in sTarget after successful encoding.
sSource Source data to encode. This can also be binary data.
nSourceLen Length in bytes of the source data (optional). Specifiy STRING_COMPLETE or omit this parameter to encode all available data.

For example, the string "testuser:testpass" is converted to "dGVzdHVzZXI6dGVzdHBhc3M=". Binary data can also be encoded in order to transport it safely over a 7-bit transport environment.

Note: The data size increases by 30% due to the encoding.

Example

dcltrans
  transaction TWebOwnAuthHeader
  var
    sUserPass : string;
    nUserPassLen : number;
  begin
    // Build your own authentication header
    WebBase64Encode(sUserPass, 200, nUserPassLen,
      "smith:paranoia{}[]~^");

    sUserPass := "Basic " + sUserPass;

    WebHeaderAdd("Authorization", sUserPass);
    WebUrl("http://standardhost/", 0.0);
  end TWebOwnAuthHeader;

Sample scripts

WebEncoding01.bdf, WebForms02.bdf