从TIdHTTP get读取标头的方法如下:
uses
IdHTTP;
var
IdHTTP: TIdHTTP;
begin
IdHTTP := TIdHTTP.Create;
var
Response: TStringList;
begin
Response := TStringList.Create;
try
IdHTTP.Get('http://www.example.com', Response);
finally
Response.Free;
end;
var
Headers: TStrings;
begin
Headers := IdHTTP.Response.RawHeaders;
// 遍历标头信息
for I := 0 to Headers.Count - 1 do
begin
// 处理每个标头
// Headers.Strings[I] 包含标头的名称和值
end;
end;
完整的代码示例:
uses
IdHTTP, Classes;
procedure ReadHeadersFromGetRequest;
var
IdHTTP: TIdHTTP;
Response: TStringList;
Headers: TStrings;
I: Integer;
begin
IdHTTP := TIdHTTP.Create;
Response := TStringList.Create;
try
IdHTTP.Get('http://www.example.com', Response);
Headers := IdHTTP.Response.RawHeaders;
for I := 0 to Headers.Count - 1 do
begin
// 处理每个标头
// Headers.Strings[I] 包含标头的名称和值
end;
finally
Headers.Free;
Response.Free;
IdHTTP.Free;
end;
end;
领取专属 10元无门槛券
手把手带您无忧上云