[code=delphi]
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.[/code]
或许可以做的再自动些,不过已经无关紧要了,因为目的已经达到,O(∩_∩)O~
转载请注明:鸟儿博客 » delphi之伪造referer下载文件