[Gambas-user] HttpClient question

Daniel daniel.campos at ...338...
Sun Jun 27 11:30:27 CEST 2004


El dom, 27-06-2004 a las 01:46, Warped Dragon -=UDIC=- escribió:
> I'm wondering how to go about making a download progress bar for the 
> HttpClient. Actually making the progress bar would be easy, I think, if I 
> knew how to find a file's size and measure how much of it has been received. 
> But the HtppClient isn't documented in the gambas wiki, and I can't seem to 
> puzzle it out on my own. Can anyone help?


HTTP protocol can show the lenght of a document in the headers, you have
to find that header:

Content-Length: 596 

(586 bytes, in this example)

The first time you receive a "Read" event, it is sure that all headers
as been received, as "Read" event raises when a piece of the body has
been received, HTTP server always sends all headers and then the body
(the "useful" part of the information, we could say). So, the first time
you receive you can look in the 'Headers' property of HttpClient (look
the HTTPGet example), looking for 'Content-Length'. That would be the
total length of the document. Then, each time you read data you can 
know the length of bytes received using 'Lof' stream method, so that
TotalReceived=TotalReceived + Lof (MyHttpObject)

Note that not all HTTP servers send that 'Content-Lenght' header, so you
have to adapt your code if that header is not received (Surely sometimes
you have seen, downloading with Mozilla, that it shows something like
'578Kb from "Unknown" ' :-)

Regards,

Daniel Campos
  


> 
> _________________________________________________________________
> STOP MORE SPAM with the MSN Premium and get 2 months FREE*    
> http://join.msn.com/?pgmarket=en-ca&page=byoa/prem&xAPID=1994&DI=1034&SU=http://hotmail.com/enca&HL=Market_MSNIS_Taglines
> 
> 
> 
> -------------------------------------------------------
> This SF.Net email sponsored by Black Hat Briefings & Training.
> Attend Black Hat Briefings & Training, Las Vegas July 24-29 - 
> digital self defense, top technical experts, no vendor pitches, 
> unmatched networking opportunities. Visit www.blackhat.com
> _______________________________________________
> Gambas-user mailing list
> Gambas-user at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user





More information about the User mailing list