http用idhttp。
ftp用idftp.
通过文件 *** 作或用tstringlist.readfromfile把文本文档载进内存,然后用pos函数判断。
网上搜一搜,这样的代码到处都是function DownloadToFile(const Url, LFile: string): Boolean
var
NetHandle: HINTERNET
UrlHandle: HINTERNET
Buffer: array[0..1024] of Char
BytesRead,WriteNumber: Cardinal
hFile: THandle
begin
Result := False
hFile := CreateFile(PChar(LFile),
GENERIC_WRITE,
0,
nil,
CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
0)
if hFile = INVALID_HANDLE_VALUE then
begin
//MsgBox(0,'创建文件失败')
Exit
end
NetHandle := InternetOpen('Delphi 5.x', INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0)
if Assigned(NetHandle) then
begin
UrlHandle := InternetOpenUrl(NetHandle, PChar(Url), nil, 0, INTERNET_FLAG_RELOAD, 0)
if Assigned(UrlHandle) then
{ UrlHandle valid? Proceed with download }
begin
SetFilePointer(hFile, 0, nil, FILE_BEGIN)
FillChar(Buffer, SizeOf(Buffer), 0)
repeat
//Result := Result + Buffer
FillChar(Buffer, SizeOf(Buffer), 0)
InternetReadFile(UrlHandle, @Buffer, SizeOf(Buffer), BytesRead)
WriteFile(hFile,Buffer, BytesRead, WriteNumber, nil)
if (BytesRead <>WriteNumber) then
begin
//MsgBox(0,'保存文件失败')
break
end
//LFileStream.Write(Buffer, BytesRead)
until BytesRead = 0
CloseHandle(hFile)
InternetCloseHandle(UrlHandle)
end
InternetCloseHandle(NetHandle)
end
end
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)