uses UrlMon;
begin
try
Result := UrlDownloadToFile(nil, PChar(source), PChar(Dest), 0, nil) = 0;
except
Result := False;
end;
end;
begin
try
Result := UrlDownloadToFile(nil, PChar(SourceFile), PChar(DestFile), 0, nil) = 0;
except
Result := False;
end;
end;
const
// URL Location
SourceFile :=
// Where to save the file
DestFile :=
begin
if DownloadFile(SourceFile, DestFile) then
begin
ShowMessage('Download succesful!');
// Show downloaded image in your browser
ShellExecute(Application.Handle,PChar('open'),PChar(DestFile),PChar(''),nil,SW_NORMAL)
end
else
ShowMessage('Error while downloading ' + SourceFile)
end;
加入如下代码:
NMHTTP1.InputFileMode := ture;
NMHTTP1.Body := '本地档案名';
NMHTTP1.Header := 'Head.txt';
NMHTTP1.OutputFileMode := FALSE;
NMHTTP1.ReportLevel := Status_Basic;
NMHTTP1.Proxy := '代理伺服器的IP位址';
NMHTTP1.ProxyPort := '代理伺服器的埠号';
With NMHTTP1.HeaderInfo do
Begin
Cookie := '';
LocalMailAddress := '';
LocalProgram := '';
Referer := '';
UserID := '用户名称';
Password := '用户口令';
End;
试试吧,Delphi的目录中有TNMHTTP控制项的例子。NT4+,Win95+,IE3+,你可以用URL Moniker的功能。
uses URLMon; ...
OleCheck(URLDownloadToFile(nil,'URL','Filename',0,nil));
beginio
DownLoadFile:=TFileStream.Create('c:\aa.rar',fmCreate);
DownLoadFile.Free;
end;
//---------------------------