我做了一个代理服务器程序,接收来自客户端的Post数据,并且转发,用Indy 9 的TIdMappedPortTCP控件,其中有如下函数,接收客户端数据:function TFormMain.ReceiveData(Athread: TIdMappedPortThread): Boolean;
{获取来自客户机的请求数据,将数据直接保存到Athread.NetData}
begin
with Athread do
begin
NetData:='';
result:=False;
try
Connection.ReadFromStack(true,-1,true);
NetData:=Connection.InputBuffer.Extract(Connection.InputBuffer.Size);
result:=true;
except
end;
end;
end;问题是,在Post数据比较大的时候,经常丢数据,比如Http头中的Content-Length: 57040
但实际得到的数据也许只有8000多,有时候是3000多,这是怎么回事呢?Indy的源代码我看了,具体如何读缓冲区的部分就不懂了,请高手们指教。
你先向客户端返回HTTP/1.0 200 OK了吗?
begin
NetData:='';
result:=False;
try
Connection.ReadFromStack(true,-1,true);
NetData:=Connection.InputBuffer.Extract(Connection.InputBuffer.Size);
result:=true;
except
end;
end;
代码绝对没错,呵呵,我这里怎么很正常。