我用的是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;
uj5u.com熱心網友回復:
先用httpdebug抓包,在ie下,從登錄到下載操作一次,分析一下,登錄和下載的報文。delphi這邊用indy模擬一下即可uj5u.com熱心網友回復:
能具體一點嗎,沒有搞過這個httpdebug是用自帶的還是下載一個uj5u.com熱心網友回復:
能具體一點嗎,或者給個QQ,我具體聯系一下你
uj5u.com熱心網友回復:
下載HTTP Debugger Pro軟體,能夠分析登錄請求的具體報文。轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/32566.html
標籤:VCL組件開發及應用
