Pascal (Lazarus/Delphi)
Pascal (Lazarus/Delphi)
HTTP GET with utf-8 URL Encoded Query Params
See more HTTP Examples
Demonstrates how to build URLs where query param values can be either URL encoded from the utf-8 representation, or from another charset such as windows-1252.Note: This example uses the new DecodeAndAppend method added in Chilkat v9.5.0.87.
Chilkat Pascal (Lazarus/Delphi) Downloads
program ChilkatDemo;
// Demonstrates using the Chilkat Pascal wrapper via the C bridge DLL.
// Builds as a console application under Lazarus (FPC) or Delphi.
{$IFDEF FPC}
{$MODE DELPHI}
{$ENDIF}
{$APPTYPE CONSOLE}
uses
{$IFDEF UNIX}
cthreads,
{$ENDIF}
SysUtils,
CkDllLoader,
Chilkat.Http,
Chilkat.StringBuilder;
// ---------------------------------------------------------------------------
procedure RunDemo;
var
success: Boolean;
nameWindows1252UrlEncoded: string;
sb1: TStringBuilder;
http: THttp;
sbUrl: TStringBuilder;
responseBody: string;
begin
success := False;
// We have the string "MÆRSK".
// This is the URL encoding of the windows-1252 representation.
nameWindows1252UrlEncoded := 'M%C6RSK';
sb1 := TStringBuilder.Create;
success := sb1.DecodeAndAppend(nameWindows1252UrlEncoded,'url','windows-1252');
http := THttp.Create;
// Here's how to send an HTTP GET where the param is the utf-8 representation that is URL encoded.
// For example: https://www.chilkatsoft.com/something?name=M%C3%A6RSK
sbUrl := TStringBuilder.Create;
sbUrl.Append('https://www.chilkatsoft.com/something?name=');
sbUrl.Append(sb1.GetEncoded('url','utf-8'));
WriteLn(sbUrl.GetAsString());
responseBody := http.QuickGetStr(sbUrl.GetAsString());
// Here's how to send an HTTP GET where the param is the windows-1252 representation that is URL encoded.
// For example: https://www.chilkatsoft.com/something?name=M%E6RSK
sbUrl.Clear();
sbUrl.Append('https://www.chilkatsoft.com/something?name=');
sbUrl.Append(sb1.GetEncoded('url','windows-1252'));
WriteLn(sbUrl.GetAsString());
responseBody := http.QuickGetStr(sbUrl.GetAsString());
sb1.Free;
http.Free;
sbUrl.Free;
end;
// ---------------------------------------------------------------------------
begin
try
RunDemo;
except
on E: Exception do
WriteLn('Unhandled exception: ', E.ClassName, ': ', E.Message);
end;
WriteLn;
{$IFDEF MSWINDOWS}
WriteLn('Press Enter to exit...');
ReadLn;
{$ENDIF}
end.