http://delphi.about.com/od/internetintranet/a/get_file_net.htm
Programmatically Download Web Documents from the Internet
Download Files, HTML pages, RSS feeds
你也可以用 其它控件indy windows api etc.
uses WinInet;
function GetInetFile (const fileURL, FileName: String): boolean;
const
BufferSize = 1024;
var
hSession, hURL: HInternet;
Buffer: array[1..BufferSize] of Byte;
BufferLen: DWORD;
f: File;
sAppName: string;
begin
result := false;
sAppName := ExtractFileName(Application.ExeName) ;
hSession := InternetOpen(PChar(sAppName), INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0) ;
try
hURL := InternetOpenURL(hSession, PChar(fileURL), nil, 0, 0, 0) ;
try
AssignFile(f, FileName) ;
Rewrite(f,1) ;
repeat
InternetReadFile(hURL, @Buffer, SizeOf(Buffer), BufferLen) ;
BlockWrite(f, Buffer, BufferLen)
until BufferLen = 0;
CloseFile(f) ;
result := True;
finally
InternetCloseHandle(hURL)
end
finally
InternetCloseHandle(hSession)
end
end;
----
var
internetFile,
localFileName: string;
begin
internetFile := 'http://z.about.com/6/g/delphi/b/index.xml';
localFileName := 'About Delphi Programming RSS Feed.xml';
if GetInetFile(internetFile, localFileName) then
ShowMessage('Download successful.')
else
ShowMessage('Error in file download.') ;
idny的话
var
i:Integer;
sl:TStringList;
begin
sl:=TStringList.Create;
sl.Text:=( IdHTTP1.Get('http://127.0.0.1/1.txt'));
for I := 0 to sl.Count - 1 do
ShowMessage(sl[i]);
sl.Free
end.