Lazarus Pascal
Lazarus Pascal
Example: Http.HasRequestHeader method
Demonstrates theHasRequestHeader method.
Chilkat Lazarus Pascal 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;
// ---------------------------------------------------------------------------
procedure RunDemo;
var
http: THttp;
b: Boolean;
begin
http := THttp.Create;
http.SetRequestHeader('X-CSRF-Token','Fetch');
b := http.HasRequestHeader('X-CSRF-Token');
if (b = True) then
begin
WriteLn('X-CSRF-Token: Yes');
end
else
begin
WriteLn('X-CSRF-Token: No');
end;
b := http.HasRequestHeader('X-Something');
if (b = True) then
begin
WriteLn('X-Something: Yes');
end
else
begin
WriteLn('X-Something: No');
end;
// The Accept and Accept-Encoding headers are default headers automatically added,
// unless the application chooses to remove by calling RemoveRequestHeader for each.
b := http.HasRequestHeader('Accept');
if (b = True) then
begin
WriteLn('Accept: Yes');
end
else
begin
WriteLn('Accept: No');
end;
// Output:
// X-CSRF-Token: Yes
// X-Something: No
// Accept: Yes
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.