Source : http://www.howto.pe.kr/zboard/zboard.php?id=delphi_tiptrick&page=1&sn1=&divpage=1&sn=off&ss=on&sc=on&select_arrange=headnum&desc=asc&no=946


unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, IdBaseComponent, IdComponent, IdTCPConnection,
  IdTCPClient, IdHTTP;

type
  TForm1 = class(TForm)
    IdHTTP1: TIdHTTP;
    Button1: TButton;
    edURL: TEdit;
    Memo1: TMemo;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
  edURL.Text := 'http://www.google.co.kr';
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  Memo1.Clear;

  try
    IdHTTP1.Head(edURL.Text);
    Memo1.Lines.Add('Server: ' + IdHTTP1.Response.Server);
    Memo1.Lines.Add('Connection: ' + IdHTTP1.Response.Connection);
    Memo1.Lines.Add('CacheControl: ' + IdHTTP1.Response.CacheControl);
    Memo1.Lines.Add('Location: ' + IdHTTP1.Response.Location);
    Memo1.Lines.Add('ContentLength: ' + IntToStr(IdHTTP1.Response.ContentLength)); // 파일 크기
    Memo1.Lines.Add('ContentEncoding: ' + IdHTTP1.Response.ContentEncoding);
    Memo1.Lines.Add('ContentLanguage: ' + IdHTTP1.Response.ContentLanguage);
    Memo1.Lines.Add('ContentType: ' + IdHTTP1.Response.ContentType);
    Memo1.Lines.Add('ContentVersion: ' + IdHTTP1.Response.ContentVersion);
    Memo1.Lines.Add('ResponseText: ' + IdHTTP1.Response.ResponseText);
    Memo1.Lines.Add('CustomHeaders: ' + IdHTTP1.Response.CustomHeaders.Text);
    Memo1.Lines.Add('ProxyConnection: ' + IdHTTP1.Response.ProxyConnection);
    Memo1.Lines.Add('ProxyAuthenticate: ' + IdHTTP1.Response.ProxyAuthenticate.Text);
    Memo1.Lines.Add('WWWAuthenticate: ' + IdHTTP1.Response.WWWAuthenticate.Text);

    // IdHTTP.Response 의 프러퍼티중 일부 파싱을 잘못하여 정보가 들어있지 않은 경우나
    // 최신의 Indy 컴포넌트가 아니어서 Response.LastModified 가 없는경우는
    // 직접 Response.RawHeaders 를 읽어 정보를 알아낼 수 있다 
    //Memo1.Lines.Add('LastModified: ' + IdHTTP1.Response.LastModified);
    Memo1.Lines.Add('RawHeaders: ' + IdHTTP1.Response.RawHeaders.Text);
  except on E: Exception do
    Memo1.Lines.Add(E.Message);
  end;
end;

end.


+ Recent posts