Delphi ActiveX
Delphi ActiveX
Get a REST Response Header Value by Index
See more REST Examples
Demonstrates Rest.ResponseHdrValue, which returns the value of the response header at a zero-based index. The same index used with ResponseHdrName gives the corresponding field name.
Background. Response headers can be enumerated by index from 0 through NumResponseHeaders minus one, after ReadResponseHeader has been called.
Chilkat Delphi ActiveX Downloads
var
success: Integer;
rest: TChilkatRest;
bTls: Integer;
bAutoReconnect: Integer;
statusCode: Integer;
numHeaders: Integer;
i: Integer;
value: 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 the response header at a zero-based index. Use the same index with
// ResponseHdrName to get the corresponding field name.
numHeaders := rest.NumResponseHeaders;
for i := 0 to numHeaders - 1 do
begin
value := rest.ResponseHdrValue(i);
if (rest.LastMethodSuccess = 0) then
begin
Memo1.Lines.Add(rest.LastErrorText);
Exit;
end;
Memo1.Lines.Add('Header ' + IntToStr(i) + ' value: ' + value);
end;