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.

相关阅读 >>

Delphi windows 编程[8] - wm_paint 消息

Delphi 自动升级组件autoupgrader简单教程

Delphi检测程序是否在优盘上运行

Delphi中怎样展开和关闭treeview的所有节点

windows 编程 窗体生成的过程

Delphi 显示程序占用内存多少

Delphi 缓冲文件流-tbufferedfilestream tfilestream 性能测试

Delphi强制应用非一次性载入的注册表设置

Delphi 使format输出百分号 %

Delphi 将label的caption内容竖向显示

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...