怎样用delphi得到真实的下载地址(200分)

  • 主题发起人 主题发起人 gfjohn
  • 开始时间 开始时间
G

gfjohn

Unregistered / Unconfirmed
GUEST, unregistred user!
如果网站有重定向下载文件,那么怎样用delphi得到真实的下载地址。
 
读Header里面的Location
 
这得看你用什么控件了……
 
用什么控件都可以,能不能说具体点,最好给个例子。
 
你用IdHTTP的话,
IdHTTP.HandleRedirects := True;
可以自己转到真实的下载地址,在事件OnRedirect中,可以得到目标网址
 
能不能给个demo,我试过OnRedirect根本没运行。
 
//Unit1.dfm
object Form1: TForm1
Left = 192
Top = 107
Width = 696
Height = 480
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -12
Font.Name = '宋体'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 12
object Button1: TButton
Left = 312
Top = 232
Width = 75
Height = 25
Caption = 'Button1'
TabOrder = 0
OnClick = Button1Click
end
object IdHTTP1: TIdHTTP
MaxLineAction = maException
AllowCookies = True
HandleRedirects = True
ProxyParams.BasicAuthentication = False
ProxyParams.ProxyPort = 0
Request.ContentLength = -1
Request.ContentRangeEnd = 0
Request.ContentRangeStart = 0
Request.Accept = 'text/html, */*'
Request.BasicAuthentication = False
Request.UserAgent = 'Mozilla/3.0 (compatible; Indy Library)'
HTTPOptions = [hoForceEncodeParams]
OnRedirect = IdHTTP1Redirect
Left = 336
Top = 192
end
end

//Unit1.pas
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient,
IdHTTP, StdCtrls;

type
TForm1 = class(TForm)
IdHTTP1: TIdHTTP;
Button1: TButton;
procedure IdHTTP1Redirect(Sender: TObject; var dest: String;
var NumRedirect: Integer; var Handled: Boolean;
var VMethod: TIdHTTPMethod);
procedure Button1Click(Sender: TObject);
private
public
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.IdHTTP1Redirect(Sender: TObject; var dest: String;
var NumRedirect: Integer; var Handled: Boolean;
var VMethod: TIdHTTPMethod);
begin
showMessage(dest);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
showmessage(idhttp1.Get('http://localhost/r.asp'));
end;

end.
 
大哥,你用的indy那个版本,我的D6带的那个怎么没你说的ProxyParams.BasicAuthentication , ProxyParams.ProxyPort ,MaxLineAction , AllowCookies ,Request.BasicAuthentication
 
没有通用的方法吧?
 
我用的是indy9,你不用管其它属性,拖一个控件放上去,只设置以下一个属性就行
HandleRedirects = True
 
大哥还是不行啊,看看你的E-Mail吧!
 
这几天出差了。回去就看。
 
有的网站是返回一个带js的网页的。不能一概而论。
 
多人接受答案了。
 
后退
顶部