【问题标题】:Problem getting the direct fileserve.com download link using indy使用 indy 获取直接 fileserve.com 下载链接时出现问题
【发布时间】:2011-06-29 16:17:54
【问题描述】:

当我尝试使用 indy (delphi 2007) 获取直接下载链接时遇到问题

我使用此代码成功使用我的高级帐户登录(fileserve.com)

procedure TForm1.Button1Click(Sender: TObject);
var
i:integer;
Data, Page : TStringList;
begin
Data := TStringList.Create;
idhttp1.OnRedirect := IdHTTP1Redirect;

idhttp1.AllowCookies := True;
idhttp1.HandleRedirects := True;
idhttp1.ProtocolVersion := pv1_1;
idhttp1.CookieManager := IdCookieManager1;
idhttp1.RedirectMaximum := 15;
idhttp1.Request.UserAgent := 'Mozilla/5.0 (compatible; MSIE 7.0; Windows NT 5.1)';

Data.Add('loginUserName=[user]&loginUserPassword=[pass]&autoLogin=&loginFormSubmit=Login');
IdHTTP1.Post('http://www.fileserve.com/login.php',Data);

idHTTP1.get('http://www.fileserve.com/file/aYkRqp3');

for i := 0 to IdCookieManager1.CookieCollection.Count - 1 do
 form1.Memo2.Lines.Add(IdCookieManager1.CookieCollection.Items[i].CookieText);

end;
procedure TForm1.IdHTTP1Redirect(Sender: TObject; var dest: string;
  var NumRedirect: Integer; var Handled: Boolean; var VMethod: string);
begin
form1.Edit1.Text := dest; //this will show the direct link after "idHTTP1.get" download the hole file
end;

我想从此链接获取直接下载链接,例如 fileserve.com/file/aYkRqp3 但是上面的代码将下载文件然后显示直接链接,我不希望我想在不下载文件的情况下获得直接链接...... fileserve 从http://www.fileserve.com/file/aYkRqp3 重定向到这样的直接链接 http://fs559dm.fileserve.com/file/aYkRqp3/MAfrTjoMNgfT44D9-2-OTNML/22c855/hex-editor-neo.exe 我只想要直接链接我怎么能做到这一点,对不起我的英语

【问题讨论】:

    标签: delphi indy


    【解决方案1】:

    为避免通过重定向下载,您可以在 TIdHTTP.OnRedirect 事件中将 TIdHTTP.HandleRedirects 设置为 False 并将 Handled 设置为 True。当 TIdHTTP.Get() 退出时,重定向的 URL 将位于 TIdHTTP.Response.Location 属性中。例如:

    procedure TForm1.Button1Click(Sender: TObject);
    var
      i:integer;
      Data, Page : TStringList;
    begin
      IdHTTP1.OnRedirect := nil;
      IdHTTP1.AllowCookies := True;
      IdHTTP1.HandleRedirects := True;
      IdHTTP1.ProtocolVersion := pv1_1;
      IdHTTP1.CookieManager := IdCookieManager1;
      IdHTTP1.RedirectMaximum := 15;
      IdHTTP1.Request.UserAgent := 'Mozilla/5.0 (compatible; MSIE 7.0; Windows NT 5.1)';
    
      Data := TStringList.Create;
      try
        Data.Add('loginUserName=[user]');
        Data.Add('loginUserPassword=[pass]');
        Data.Add('autoLogin=');
        Data.Add('loginFormSubmit=Login');
        IdHTTP1.Post('http://www.fileserve.com/login.php', Data);
      finally
        Data.Free;
      end;
    
      IdHTTP1.HandleRedirects := False;
      IdHTTP1.OnRedirect := IdHTTP1Redirect;
      IdHTTP1.Get('http://www.fileserve.com/file/aYkRqp3');
    
      Edit1.Text := idHTTP1.Response.Location;
      for i := 0 to IdCookieManager1.CookieCollection.Count - 1 do
        Memo2.Lines.Add(IdCookieManager1.CookieCollection.Items[i].CookieText);
    end;
    
    procedure TForm1.IdHTTP1Redirect(Sender: TObject; var dest: string; var NumRedirect: Integer; var Handled: Boolean; var VMethod: string);
    begin
      Handled := True;
    end; 
    

    【讨论】:

    • 非常感谢您的帮助,您很棒!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-26
    • 1970-01-01
    • 1970-01-01
    • 2017-09-09
    • 2021-03-09
    • 2013-09-02
    相关资源
    最近更新 更多