工程中加:
Memo1: TMemo;
Button1: TButton;两个
在uses中加入wininet,windows;
implementation
{$R *.dfm}
function GetWebPage(const Url: string):string;
var
Session,
HttpFile:HINTERNET;
szSizeBuffer:Pointer;
dwLengthSizeBuffer:DWord;
dwReserved:DWord;
dwFileSize:DWord;
dwBytesRead:DWord;
Contents:PChar;
begin
Session:=InternetOpen('',0,niL,niL,0);
HttpFile:=InternetOpenUrl(Session,PChar(Url),niL,0,0,0);
dwLengthSizeBuffer:=1024;
HttpQueryInfo(HttpFile,5,szSizeBuffer,dwLengthSizeBuffer,dwReserved);
GetMem(Contents,dwFileSize);
InternetReadFile(HttpFile,Contents,dwFileSize,dwBytesRead);
InternetCloseHandle(HttpFile);
InternetCloseHandle(Session);
Result:=StrPas(Contents);
form1.Memo1.Lines.Add(Contents);
FreeMem(Contents);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
GetWebPage(pchar('http://www.baidu.com'));
end;
posted on 2009-02-09 03:36
小叶子 阅读(1395)
评论(2) 编辑 收藏 引用 所属分类:
windows API函数