收到浏览器请求一个文件的信息,如何分段连续的返回数据给浏览器,例如文件大小50M,一次返回50K,直到传完断开连接

解决方案 »

  1.   

    我是在IdHTTPServerCommandGet里发送数据,AResponseInfo.ContentStream:=lStream一次发送只有50K,怎么循环发送?
      

  2.   

    试试
    procedure TForm5.IdHTTPServer1CommandGet(AContext: TIdContext;
      ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
    begin
    AContext.Connection.IOHandler.SendBufferSize := 50 * 1024;
    AResponseInfo.ServeFile(AContext,FileName (*预发送的文件的文件名*) );
    end;
      

  3.   

    这个代码是INDY10的吧,我用的是9,10我测试的时候取不出aRequestInfo.ContentRangeStart,ARequestInfo.ContentLength。
      

  4.   

    ARequestInfo.Range或者其它没有提供特定名称属性的可以从RawHeaders当中取。
      

  5.   

    9的话按照你的写法lStream一次读入50K
    AResponseInfo.ContentStream:=lStream;
    AResponseInfo.WriteContent;
    INDY开源的,你可以看他的处理流程
    try
                    if ContinueProcessing then begin
                      DoCommandGet(AThread, LRequestInfo, LResponseInfo);//你执行的事件
                    end;
                  except
                    on E: Exception do begin
                      LResponseInfo.ResponseNo := 500;
                      LResponseInfo.ContentText := E.Message;
                    end;
                  end;
                  // Write even though WriteContent will, may be a redirect or other
                  if not LResponseInfo.HeaderHasBeenWritten then begin
                    LResponseInfo.WriteHeader;
                  end;
                  // Always check ContentText first
                  if (Length(LResponseInfo.ContentText) > 0)
                   or Assigned(LResponseInfo.ContentStream) then begin
                    LResponseInfo.WriteContent;                   //发出
                  end;