unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ComCtrls, StdCtrls, ExtCtrls, Psock, NMHttp;
type
TForm1 = class(TForm)
NMHTTP1: TNMHTTP;
Panel1: TPanel;
Edit1: TEdit;
Button1: TButton;
Memo1: TMemo;
Label1: TLabel;
Memo2: TMemo;
Label2: TLabel;
Label3: TLabel;
StatusBar1: TStatusBar;
Edit2: TEdit;
Label4: TLabel;
Button2: TButton;
Timer1: TTimer;
Button3: TButton;
Panel2: TPanel;
Label5: TLabel;
Edit3: TEdit;
Label6: TLabel;
procedure Button1Click(Sender: TObject);
procedure NMHTTP1Connect(Sender: TObject);
procedure NMHTTP1ConnectionFailed(Sender: TObject);
procedure NMHTTP1Disconnect(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
i:integer;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
begin
Memo1.Clear ;
Memo2.Clear ;
NMHTTP1.Get (Edit1.text);
Memo1.text := NMHTTP1.Header ;
Memo2.text := NMHTTP1.Body ;
end;
procedure TForm1.NMHTTP1Connect(Sender: TObject);
begin
StatusBar1.SimpleText := 'Connect';
end;
procedure TForm1.NMHTTP1ConnectionFailed(Sender: TObject);
begin
StatusBar1.SimpleText := 'ConnectionFailed';
end;
procedure TForm1.NMHTTP1Disconnect(Sender: TObject);
begin
StatusBar1.SimpleText := 'Disconnect';
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
Timer1.Enabled := true ;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
//Edit3.text里填入标识,一般为 200 (访问成功)
if (pos(Edit3.text,Memo1.Lines.Strings[0])>0) then
begin
Memo1.Clear;
Memo2.Clear ;
NMHTTP1.Get (Edit1.text);
Memo1.Text := NMHTTP1.Header ;
Memo2.text := NMHTTP1.Body ;
i := i + 1 ;
Label5.Caption := '点击'+IntToStr(i)+'次';
end;
if i=StrToInt(Edit2.text) then
begin
Timer1.Enabled := False;
Edit2.text := '1';
i := 0;
end;
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
Timer1.Enabled := False;
end;
end.