我用的是delphi7.0开发的,目前有一个需求,我需要通过http下载一个指定文件,但是这个文件
直接调用 DownloadFile(SourceFile, DestFile) 这个函数,没有会话信息,自动重定向到登录界面,不能通过验证,造成文件获取失败。
单独在IE浏览器,登录后手工复制地址能够下载该文件,但是登录后运行DELPHI后台程序 ,还是下载获得不到那个文件,取下来的文件仅仅是重定向后的首页,我想用delphi 写怎么写入会话session,让我能够取到那个文件。Uses URLMon, ShellApi; 
function DownloadFile(SourceFile, DestFile: string): Boolean; 
begin 
try 
Result := UrlDownloadToFile(nil, PChar(SourceFile), PChar(DestFile), 0, nil) = 0; 
except 
Result := False; 
end; 
end; procedure TForm1.Button1.Click(Sender: TObject); 
const 
// URL Location 
SourceFile := 'http://www.google.com/intl/de/images/home_title.gif'; 
// Where to save the file 
DestFile := 'c:\temp\google-image.gif'; 
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;