unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, StdCtrls,wininet, ExtCtrls;
type
TForm1 = class(TForm)
Memo1: TMemo;
Edit1: TEdit;
Button1: TButton;
StatusBar1: TStatusBar;
Label1: TLabel;
Label2: TLabel;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
urlsite:string;
hinternet
ointer;
hopenurl
ointer;
bloop:boolean;
lpbuffer:array[0..2048] of char;
dwnumberofbytesread,all_time1,all_time2:dword;
sbuffer:string;
qianzhui:string;
begin
qianzhui:=copy(edit1.Text,0,7);
if (qianzhui<>'http://') then
edit1.Text:='http://'+edit1.Text;
all_time1:=gettickcount;
hinternet:=internetopen(pchar('application'),internet_open_type_preconfig,nil,nil,internet_flag_no_cache_write);
if (hinternet<>nil) then
begin
internetsetoption(hinternet,internet_option_connect_timeout,pointer(4000),4);
internetsetoption(hinternet,internet_option_connect_retries,pointer(5),1);
internetsetoption(hinternet,internet_option_send_timeout,pointer(4000),4);
internetsetoption(hinternet,internet_option_receive_timeout,pointer(4000),4);
internetsetoption(hinternet,internet_option_data_send_timeout,pointer(4000),4);
internetsetoption(hinternet,internet_option_data_receive_timeout,pointer(4000),4);
urlsite:=edit1.text;
hopenurl:=internetopenurl(hinternet,pchar(urlsite),nil,0,internet_flag_reload,$0);
if (hopenurl<>nil) then
begin
bloop:=true;
sbuffer:='';
while bloop do
begin
lpbuffer:='';
internetreadfile(hopenurl,@lpbuffer,sizeof(lpbuffer),dwnumberofbytesread);
if dwnumberofbytesread=0 then
bloop:=false
else
sbuffer:=sbuffer+strpas(lpbuffer);
end;
memo1.clear;
memo1.lines.add(sbuffer);
statusbar1.panels[0].text:='open url ok';
end
else
statusbar1.panels[0].text:='error';
end;
if (hopenurl<>nil) then internetclosehandle(hopenurl);
if (hopenurl<>nil) then internetclosehandle(hinternet);
all_time2:=gettickcount;
edit1.SetFocus;
label1.Caption:='完成时间为: '+ inttostr(all_time2-all_time1)+' ';
end;
end.