作者:傻猫
发布时间:2010-08-19 12:58:09
分类:Delphi
No Comments
85 Views
以前用indy组件时,可以直接设置indy的Request.Referer值,现在用ICS HttpCli 组件,发现居然没有Referer这个属性,我操,百度,Google全都搜索不到,然后向高手阳光小猪求教,原来HttpCli有一个Reference的属性,这个就中Referer值,我日哦,换个全称的马甲,居然让哥认不到了。
indy.Referer = HttpCli.Reference
作者:傻猫
发布时间:2010-08-18 21:58:42
分类:Delphi
No Comments
97 Views
读取UTF-8格式的文件内容
function LoadUTF8File(AFileName: string): string;
var ffileStream:TFileStream;
fAnsiBytes: string;
S: string;
begin
ffileStream:=TFileStream.Create(AFileName,fmOpenRead);
SetLength(S,ffileStream.Size);
ffileStream.Read(S[1],Length(S));
fAnsiBytes:= UTF8Decode(Copy(S,4,MaxInt));
Result:= fAnsiBytes;
end;
写入UTF-8编码格式的文件
procedure SaveUTF8File(AContent:string;AFileName: string);
var ffileStream:TFileStream;
futf8Bytes: string;
S: string;
begin
ffileStream:=TFileStream.Create(AFileName,fmCreate);
futf8Bytes:= UTF8Encode(AContent);
S:=#$EF#$BB#$BF;
ffileStream.Write(S[1],Length(S));
ffileStream.Write(futf8Bytes[1],Length(futf8Bytes));
ffileStream.Free;
end;
作者:傻猫
发布时间:2010-08-18 21:13:33
分类:Delphi
No Comments
90 Views
要限制idhttp的速度,必须使用IdInterceptThrottler来做,放一个IdInterceptThrottler和Idhttp组件,设置TIdHTTP的Intercept属性为TIdInterceptThrottler。
TIdInterceptThrottler有三个速度限制的属性:
BitsPerSec:平均速度
RecvBitsPerSec:控制接收速度
SendBitsPerSec:发送的速度
作者:傻猫
发布时间:2010-08-18 21:10:15
分类:Delphi
No Comments
54 Views
现在的下载软件一般都是多线程,多资源的下载模式,本文用ICS中的TMultipartHttpDownloader组件实现多线程,单资源的分块下载模式,鲁大师的升级就是这样的原理,可以参考.
先看组件的几个事件:
HTTPRequestDone(Sender: TObject; ErrorCode: Integer; const Reason: string);
下载完成事件,在这里可以释放下载的文件流
FMultiPartHTTP.FileStream.Free;
FMultiPartHTTP.FileStream := nil;
HTTPShowStats(Sender: TObject);
下载显示状态信息事件
'已下载(MB):' + Format('%2f',[FMultiPartHTTP.TotalCount / 1024 / 1024]) +
' 完成:' + Format('%3.0f', [FMultiPartHTTP.PercentDone])+'%' +
' 速度(KB/秒):' + Format('%6.2f', [FMultiPartHTTP.CurSpeed]) +
' 耗时:' + FormatDateTime('hh:nn:ss', FMultiPartHTTP.ElapsedTime);
下面2个事件和进度条有关,ICS自带了个下载进度条
HTTPProgressAddSegment(Sender: TObject; StartOffset, ASpan, InitPos: Int64);
ASpan分段大小,InitPos分段开始大小, StartOffset,分段开始大小
HTTPProgressSetPosition(Sender: TObject;Index: Integer; Position: Int64);
Index第几个分段 Position 分段已下载的大小
下面是用法,非常简单:
FMultiPartHTTP.URL:=下载文件地址;
FMultiPartHTTP.PartCount:=分块个数;
FMultiPartHTTP.FileStream:=TFileStream.Create('下载本地文件名',fmCreate);
FMultiPartHTTP.Start;
注意:PartCount要大于1,这个组件支持断网断点下载,如果要控制下载的线程数量需要改ICS的源代码
作者:傻猫
发布时间:2010-08-18 21:08:41
分类:Delphi
No Comments
29 Views
procedure THttpPostForm.PostButtonClick(Sender: TObject);
var
Data : String;
begin
Data := 'FirstName=' + UrlEncode(Trim('test')) + '&' +
'LastName=' + UrlEncode(Trim('test123')) + '&' +
'Submit=';
HttpCli1.SendStream := TMemoryStream.Create;
HttpCli1.SendStream.Write(Data[1], Length(Data));
HttpCli1.SendStream.Seek(0, 0);
HttpCli1.RcvdStream := TMemoryStream.Create;
HttpCli1.URL := Trim('URL');
HttpCli1.PostAsync;
end;
在RequestDone事件中接收和释放对象
procedure THttpPostForm.HttpCli1RequestDone(
Sender : TObject;
RqType : THttpRequest;
ErrCode : Word);
var
Data : String;
begin
HttpCli1.SendStream.Free;
HttpCli1.SendStream := nil;
if ErrCode <> 0 then //有异常
begin
HttpCli1.RcvdStream.Free;
HttpCli1.RcvdStream := nil;
Exit;
end;
if HttpCli1.StatusCode <> 200 then //返回错误
begin
HttpCli1.RcvdStream.Free;
HttpCli1.RcvdStream := nil;
Exit;
end;
HttpCli1.RcvdStream.Seek(0, 0);
SetLength(Data, HttpCli1.RcvdStream.Size);
HttpCli1.RcvdStream.Read(Data[1], Length(Data));
end;
作者:傻猫
发布时间:2010-08-16 15:49:18
分类:Delphi
2 Comments
78 Views
由于老版本的Indy对ssl支持有问题,好像是某些不支持,同样的代码,安装了新版Indy10.5.7就可以完美运行,但是indy 10.2.5,indy 9就不行,欧卖疙瘩。前一篇鸟语你看懂了没有?我研究了大半天,安装了好几次,始终没有成功,老是报错,相当郁闷。最后还是按照老办法安装成功。
经过本人实践得真理:以下安装适合Delphi7,Delphi2006,Delphi2007 安装Indy组件,由于默认安装开始工具后,自带了Indy组件,但是都是低版本的,要安装最新版的Indy只有自己安装。
阅读剩余部分...
作者:傻猫
发布时间:2010-08-16 14:28:57
分类:Delphi
No Comments
55 Views
Because Indy is changing fairly rapidly, and because there are problems with the version of Indy that shipped with RAD Studio 2010, I found that I had to download and compile a new version of Indy. Although that isn't too hard, the documentation is scattered all over, and there is no comprehensive source of information. Searching through all of this, I wasted quite a number of hours. To save others (and save myself when I have to do it again), I wanted to post a set of instructions.
None of the information here is original. I take credit for nothing, but I take responsibility for all of the errors. Please post corrections, for the benefit of all. I greatly appreciate the contributions of the Indy developers and experts.
My setup is RAD Studio 2010, including both Delphi and C++ Builder. I have only passing knowledge of Delphi, as C++ is what I mostly use. However, C++ Builder, by itself, is poorly documented, since Embarcadero includes most of the demos and documentation for Delphi, so I got the combined RAD Studio product. That is fortunate, since it is much easier to compile Indy using the Delphi personality than with C++ Builder. These instructions are for replacing Indy Tiburon version 140 with a new version of Indy Tiburon 140.
阅读剩余部分...
作者:傻猫
发布时间:2010-08-11 18:29:53
分类:Delphi
4 Comments
37 Views
在DELPHI盒子与DELPHI群里看到的,据说只感染DELPHI7以下的版本(包含DELPHI7),貌似N多人中招了。感染此病毒后,所有用DELPHI编译的程序全都有感染能力。
如果在 C:\Program Files\Borland\Delphi7\Lib 发现有 SysConst.bak (12KB) 和
SysConst.dcu (18KB)
文件: C:\Program Files\Borland\Delphi7\Lib\sysconst.bak
大小: 11658 字节
修改时间: 2002年8月9日, 22:00:00
MD5: 957D629F2E4C38B9FA2AC911E352FC82
SHA1: 859EFAF4C24AF89E2B06922912D1081BAD349E7C
CRC32: 004EBB9D
文件: C:\Program Files\Borland\Delphi7\Lib\sysconst.dcu
大小: 18207 字节
修改时间: 2002年8月9日, 22:00:00
MD5: 89DD28E7C1EAEAE1793D9354E7C38D21
SHA1: F7EF5B9C3C85FF01299556C5546CAD511CA9F5A8
那么恭喜你,中招了。
原版下载:SysConst.rar
阅读剩余部分...
作者:傻猫
发布时间:2010-08-11 17:56:55
分类:Delphi
No Comments
32 Views
1、伪造来源地址:使用IdHttp可以伪造这个来源地址,而且很简单,只要在访问某地之前加上一句:
IdHttp1.Request.Referer := 'http://www.3464.com/';那么来源地址就变成了http://www.3464.com/而不是你实际的来源地址了。
2、Cookie欺骗:
如何用idhttp提交自己构造过的Cookie
我不知道的是:如果把自己构造过的Cookie传给idhttp让它提交。
比如站点 http://www.aaa.com 是要cookie的。
我已经在程序上放了idhttp和IdCookieManager。
我get http://www.aaa.com 后,idhttp通过IdCookieManager已经得到当前站点的Cookie了。
我可以用
for i := 0 to IdCookieManager1.CookieCollection.Count - 1 do
memo1.Lines.Add(IdCookieManager1.CookieCollection.Items[i].CookieText);
得到。
现在,如果我想更改这个cookie,或者说我想按这个Cookie的格式重新写一个,再用idhttp进行post。我应该怎么做?用途是Cookie欺骗等。
如:得到的Cookie为:skin=2; ASPSESSIONIDSQTSABQD=IEMKPIDBKKMEEKEHLLOIJJON; UserCode=3CA001D63984E6115FE55681%2E95
我更改为:skin=123; ASPSESSIONIDSQTSABQD=IEMKPIDBKKMEEKEHLLOIJJON; UserCode=3CA001D63984E6115FE55681%2E95
我再post
阅读剩余部分...
作者:傻猫
发布时间:2010-08-05 11:10:04
分类:Delphi
No Comments
19 Views
使用IdHTTP组件的一个问题
使用IdHTTP.Get(URL) 理论上应该可以获得这个URL的源代码。
但是为什么有些网页可以获得,而有些网页出现了“HTTP/1.1 302 Object moved”的错误呢?
原因是:这个网页采用了response.rediect 跳转到另一个页面去了。
而这个跳转的页面时可以访问到的/。
将IdHTTP的属性HandleRedirects 设为true. 就可以解决这个问题啦。
- 1
- 2
- 3
- 4
- ...
- 18
- »