本文整理自网络,侵删。
今天去了某经常去下载文件的地方,居然不能通过迅雷下载,简单的测试了下发现是检查了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 shgetfileinfo函数获取任何文件大图标
Delphi xe5实现按android的back键无法退出关闭程序
Delphi 使用firedac的tfdscript组件执行文件中描述的sql语句
更多相关阅读请进入《Delphi》频道 >>