Delphi ActiveX
Delphi ActiveX
Get a REST Response Header by Name
See more REST Examples
Demonstrates Rest.ResponseHdrByName, which returns the value of a response header field by name. Header field names are case-insensitive.
Background. Response headers are available after ReadResponseHeader has read the status line and headers. Lookup by name is convenient when a specific header, such as Content-Type, is needed.
Chilkat Delphi ActiveX Downloads
var
success: Integer;
rest: TChilkatRest;
bTls: Integer;
bAutoReconnect: Integer;
statusCode: Integer;
contentType: WideString;
begin
success := 0;
rest := TChilkatRest.Create(Self);
bTls := 1;
bAutoReconnect := 1;
success := rest.Connect('example.com',443,bTls,bAutoReconnect);
if (success = 0) then
begin
Memo1.Lines.Add(rest.LastErrorText);
Exit;
end;
success := rest.SendReqNoBody('GET','/api/items/123');
if (success = 0) then
begin
Memo1.Lines.Add(rest.LastErrorText);
Exit;
end;
statusCode := rest.ReadResponseHeader();
if (statusCode < 0) then
begin
Memo1.Lines.Add(rest.LastErrorText);
Exit;
end;
// Return the value of a response header field by name. Header field names are case-insensitive.
contentType := rest.ResponseHdrByName('Content-Type');
if (rest.LastMethodSuccess = 0) then
begin
Memo1.Lines.Add(rest.LastErrorText);
Exit;
end;
Memo1.Lines.Add('Content-Type: ' + contentType);