Sample code for 30+ languages & platforms
Lazarus Pascal

Example: Http.QuickGetStr method

Demonstrates the QuickGetStr 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.Http;

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

procedure RunDemo;
var
  http: THttp;
  str: string;

begin
  http := THttp.Create;

  //  Keep the response body if there's an error.
  http.KeepResponseBody := True;

  //  Send the HTTP GET and return the content in a string.
  str := http.QuickGetStr('https://www.chilkatsoft.com/helloWorld.json');
  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(http.LastResponseBody);
        end;
      Exit;
    end;

  WriteLn(str);
  WriteLn('Success');


  http.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.