wwHTTP::OnHttpBufferUpdate

This method can be used to display progress information on downloads. It gets called whenever the receive buffer is updated on an HTTPGetEx update.

To perform buffer updates in this fashion either subclass wwIPStuff or place wwIPStuff as an object on a form or container. Then implement the OnHTTPBufferUpdate() method as shown in the example with your custom operations on each action. Use the lnBufferReads parameter to determine what action to take:

0 - HTTP Header is sent
-1 - The HTTP request was completed or cancelled. (lHttpCancelDownload is set if cancelled)

Any other value greater than 0 is the number of times OnHTTPBufferUpdate was called in which case you can check the other parameters for the current download size and current chunk of data.

o.onhttpbufferupdate(lnBytesDownloaded,lnBufferReads,lcCurrentChunk)

Remarks

Be careful with what kind of code you put into this 'event' method since it fires on every buffer update. You should minimize the amount of code that fires to handle each of the request chunks.

If you want things like Cancel buttons you will need to use DOEVENTS in the code to allow the click events to fire. Note that using DOEVENTS can slow down your application, especially if you're using any version of VFP prior to VFP 7.

I also suggest that you increase your buffer size so that this event doesn't fire so frequently. Increasing nHTTPWorkBufferSize size can significantly improve the performance of HTTP operations.

Only applies if the buffer size in the HTTPGetEx() call is set to 0 (Automatic sizing).

Example

oHTTP = CREATE("wwHTTPCustom")
oHTTP.AddPostKey("Key","Value")
lcContent = oHTTP.HTTPGet("http://someurl.com/default.asp")

ShowHTML(lcContent)

RETURN


*** Example assumes running in a form
*** with method for status display
DEFINE CLASS wwHTTPCustom as wwHTTP

*** Save Content Size
nContentSize = 0

FUNCTION OnHTTPBufferUpdate
LPARAMETERS lnbytes,lnbufferreads,lccurrentchunk

DO CASE
  *** If this is the 0 chunk it's HTTP Header
  CASE lnBufferReads = 0
       *** 0 - HTTP Header retrieved
       THIS.nContentSize = ;
           VAL( EXTRACT(lcCurrentChunk,CHR(13)+CHR(10) + "Content-length: ",CHR(13)) )

       *** Depending on size of content adjust the input buffer
       *** Smaller buffer means more frequent updates, but slower operation
       DO CASE 
         CASE THIS.nContentSize > 90000
              THIS.nHTTPWorkBufferSize = 16484
         CASE THIS.nContentSize > 40000 
              THIS.nHTTPWorkBufferSize = 8182
       ENDCASE

  CASE lnBufferReads = -1
	   *** Completed or Cancelled
	   IF THIS.lHttpCancelDownload
		  SetOnlineMessage("Request Cancelled...")
	   ENDIF

       RETURN
  OTHERWISE
       DoEvents
ENDCASE

*** Call Form method to display progress
*** Replace with your progress display code here
THISFORM.SetOnlineMessage("Received from " + THISFORM.cWebServer + ":" +CHR(13) +;
                          LTRIM( TRANSFORM(lnBytes,"999,999,999") ) + " of " +;
                          LTRIM(TRANSFORM(THIS.nContentSize,"999,999,999"))+ " bytes",.F.)
               
ENDDEFINE

See also:

Class wwHTTP | wwHTTP::lHttpCancelDownload | wwHTTP::HTTPCanceldownload


  Last Updated: 3/1/2007 | © West Wind Technologies, 2008