uses WinInet; 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); FreeMem(Contents); end; procedure TForm1.Button1Click(Sender: TObject); begin edit1.Text := GetWebPage('http://www.baidu.com/'); end; |
转载请注明:Delphi7» Delphi7读取网址内容
标签: