delphi之伪造referer下载文件  
官方Delphi 学习QQ群: 682628230(三千人)
频道

delphi之伪造referer下载文件


今天去了某经常去下载文件的地方,居然不能通过迅雷下载,简单的测试了下发现是检查了referer,所以花点时间做了下面的这个东西。

unit Unit1; 
 
interface 
 
uses 
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, 
  Dialogs, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient, 
  IdHTTP, IdAntiFreezeBase, IdAntiFreeze, StdCtrls; 
 
type 
  TForm1 = class(TForm) 
    IdHTTP1: TIdHTTP; 
    Button1: TButton; 
    IdAntiFreeze1: TIdAntiFreeze; 
    Label1: TLabel; 
    Memo1: TMemo; 
    Label2: TLabel; 
    procedure Button1Click(Sender: TObject); 
    procedure FormCreate(Sender: TObject); 
  private 
    { Private declarations } 
  public 
    { Public declarations } 
  end
 
var 
  Form1: TForm1; 
  i:Integer; 
 
implementation 
 
{$R *.dfm} 
 
procedure TForm1.Button1Click(Sender: TObject); 
var 
MyStream:TMemoryStream; 
downloadurl,datex:string
begin 
      while i<230 do //文本只有229行哈~~ 
      begin 
downloadurl:=memo1.lines[i-1];//取出memo中的数值,memo1.lines[i-1]是第i行 
IdAntiFreeze1.OnlyWhenIdle:=False;//设置使程序有反应. 
MyStream:=TMemoryStream.Create; 
IdHTTP1.Request.Referer:='http://www.nobird.org/';//这里设置的referer的地址。 
datex:= FormatDateTime('yyyymmddhhnnss',now());//时间命名,免得重复 
try 
IdHTTP1.Get(downloadurl,MyStream); 
except 
Label1.Font.Color:=clBlue; 
Label1.Caption:='文件'+datex+'.key下载失败'
MyStream.Free; 
end
MyStream.SaveToFile('c:\456\'+ datex +'.rar'); 
MyStream.Free; 
Label1.Font.Color:=clRed; 
Label1.Caption:='文件'+datex+'.rar下载完成'
Inc(i); 
Label2.Caption:='已经下载了'+inttostr(i)+'个文件'
sleep(1000);//休息下,呵呵 
end
if i>229  then 
begin 
 
  ShowMessage('结束啦'); 
  Exit; 
  end
end
 
 
procedure TForm1.FormCreate(Sender: TObject); 
begin 
//Label1.Caption := FormatDateTime('yyyymmddhhnnss',now()); 
Memo1.Lines.LoadFromFile('en1.txt');//读取事先做好的列表,手动处理获取的。 
Label1.Caption:=inttostr(memo1.Lines.count);//获取memo1的行数 
  i:=1
end
end.

推荐分享
图文皆来源于网络,内容仅做公益性分享,版权归原作者所有,如有侵权请告知删除!
 

Copyright © 2014 DelphiW.com 开发 源码 文档 技巧 All Rights Reserved
晋ICP备14006235号-8 晋公网安备 14108102000087号

执行时间: 0.043916940689087 seconds