Sample code for 30+ languages & platforms
Lazarus Pascal

Example: Http.QuickGetSb method

Demonstrates the QuickGetSb method.

Chilkat Lazarus Pascal Downloads

Lazarus Pascal
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.StringBuilder,
  Chilkat.Http;

// ---------------------------------------------------------------------------

procedure RunDemo;
var
  success: Boolean;
  http: THttp;
  sb: TStringBuilder;

begin
  success := False;

  http := THttp.Create;

  //  Send the HTTP GET and return the content in a StringBuilder
  sb := TStringBuilder.Create;
  success := http.QuickGetSb('https://www.chilkatsoft.com/helloWorld.json',sb);
  if (http.LastMethodSuccess = False) then
    begin
      if (http.LastStatus = 0) then
        begin
          //  Communications error.  We did not get a response.
          WriteLn(http.LastErrorText);
        end
      else
        begin
          WriteLn('Response status code: ' + http.LastStatus);
          WriteLn('Response body error text:');
          WriteLn(sb.GetAsString());
        end;
      Exit;
    end;

  //  The downloaded content:
  WriteLn(sb.GetAsString());
  WriteLn('Success');


  http.Free;
  sb.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.