Le 09/01/2011 16:08, Jean-Paul Passama a écrit :
Le 09/01/2011 15:49, Arno Garrels a écrit :
Jean-Paul Passama wrote:
Hi,

I'm trying to have a progress bar working during a file download by
HttpClient.Get (and HttpClient.RcvdStream).

I've seen the OnDocData that seems to receive the length of data
downloaded. Unfortunaly, the data length isn't really the size of the
piece of file downloaded because the packed received include the HTTP
protocol and the data.

Is a way to know :
- the size of the entire file (before starting the download)
Quoted from http://www.rfc-editor.org/rfc/rfc2068.txt:
"An HTTP/1.1 server may also establish persistent connections with
HTTP/1.0 clients upon receipt of a Keep-Alive connection token.
However, a persistent connection with an HTTP/1.0 client cannot make
use of the chunked transfer-coding, and therefore MUST use a
Content-Length for marking the ending boundary of each message."

So it should be possible to force the server to send a content-length
header. In event OnDocBegin property ContentLength should return that
value.

In the Event OnDocBegin , no such property (ContentLength) :

procedure TMyForm.HttpCli1DocBegin(Sender: TObject);

And THttpClient doesn't have this property.

So where I could retrieve this property from ?

Thank you
JP

Sorry for that message, I tried and it works :

procedure TClubFTP.HttpCli1DocBegin(Sender: TObject);
var x : integer;
begin
x := (Sender as THttpCli).ContentLength;
if (x <> -1) and (SizeFile = 0)
then begin
     SizeFile := x;
     end;
end;

The ProgressBar works with RcvdStream.Position

procedure TClubFTP.HttpCli1DocData(Sender: TObject; Buffer: Pointer;
  Len: Integer);
var x : longint;
begin
x := HttpCli1.RcvdStream.Position * 100 div SizeFile;
if x > 0
then PB.Position := x;
end;

Thank you
JP



--
To unsubscribe or change your settings for TWSocket mailing list
please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be


--
To unsubscribe or change your settings for TWSocket mailing list
please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be

Reply via email to