我也出了这个问题,几乎一摸一样。
在线程里新create一个TNMHTTP实例,然后让它下载,
结果对小网页一点问题没有,可是一旦下载大网页,总是下不全就停住不动了。
比如 www.sohu.com, 共63727,下了 56690就不动了,几乎每次都这样。
可是像 www.263.net 44xxx, www.sina.com.cn 54xxx 等等都没问题。
后来我特意验证了一下动态建立的TNMHTTP实例的特性,
结果,在一个极为简单的程序里,静态的实例没问题,
动态建立实例就不行,经常出 EAbortError "Socket Caption Aborted"
下面是源程序:
大家帮忙看看,给点意见:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Psock, NMHttp;
type
TForm1 = class(TForm)
Button1: TButton;
Label1: TLabel;
NMHTTP1: TNMHTTP;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure NMHTTP1PacketRecvd(Sender: TObject);
procedure NMHTTP1HostResolved(Sender: TComponent);
procedure NMHTTP1Connect(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
//点击Button1,用静态的TNMHTTP实例连接 sohu
procedure TForm1.Button1Click(Sender: TObject);
begin
Label1.Caption:='Clicked';
with NMHTTP1do
begin
InputFileMode:=False;
OutPutFileMode:=False;
ReportLevel:=Status_Basic;
Get('http://www.sohu.com');
end;
end;
//点击Button2,建立一个动态的TNMHTTP实例,连接 sohu
procedure TForm1.Button2Click(Sender: TObject);
begin
if NMHTTP1<>nil then
NMHTTP1.Free;
NMHTTP1:=TNMHTTP.Create(nil);
with NMHTTP1do
begin
InputFileMode:=False;
OutPutFileMode:=False;
ReportLevel:=Status_Basic;
TimeOut:=5000;
OnConnect:=NMHTTP1Connect;
OnHostResolved:=NMHTTP1HostResolved;
OnPacketRecvd:=NMHTTP1PacketRecvd;
Get('http://www.sohu.com');
end;
end;
//最后是TNMHTTP实例的Events
procedure TForm1.NMHTTP1PacketRecvd(Sender: TObject);
begin
Label1.Caption := IntToStr(NMHTTP1.BytesRecvd)+' of '+IntToStr(NMHTTP1.BytesTotal)+' retrieved';
end;
procedure TForm1.NMHTTP1HostResolved(Sender: TComponent);
begin
Label1.Caption := 'Host Resolved';
end;
procedure TForm1.NMHTTP1Connect(Sender: TObject);
begin
Label1.Caption := 'Connected'
end;
end.