wwHTTP::HttpGetExAsync

Allows you to retrieve HTTP content asynchronously and store the result value into a file. Client code can poll for the result file to retrieve the Async content.

o.HTTPGetExAsync(tcPage,tcResultFile,tnResultSize,tcHeaders)

Return Value

nothing

Parameters

tcPage
Link on the server to load. (/Default.htm)

tcResultFile
Path to a file that will be created with the output from the request.

tnResultSize
The size of the data to be written to the file. This is required, so be sure to specify a size that's large enough. You should be careful not to use too large of a buffer either because memory will be preallocated for this amount of data.

tcHeaders
HTTP Headers to set on the request.

tnSecondsBeforeDelete
Number of seconds for the file to stick around. The Async thread will stick around this long after creating the file and then delete it automatically.

Remarks

The result file basically controls the lifetime of the async thread as well as the response communication with the calling application. When the file can be opened ( lnHandle=FOPEN(tcFileName,0) with lnHandle being a positive value or File2Var() returning a string ) the thread is done writing the data from the HTTP request, otherwise the file is still locked and the data not complete. Once the file's been written completely the thread will wait for tnSecondsBeforeDelete seconds before erasing the file or until the file is deleted externally by your app. Once either of these events occur the thread is released.

If you will display the result file or otherwise persist the data it's recommended you copy it to a new location or a string and then delete the original.

If you quit Visual FoxPro while an async thread is active, VFP will crash!

Example

CLEAR
DO WCONNECT

loIP = CREATEOBJECT("wwHTTP")
loIP.HTTPConnect("www.west-wind.com")

loIP.AddPostkey("FirstName","Rick")
loIP.AddPostkey("Company",TIME())
loIP.AddPostKey("LastName","STRAHL")

lcFile = SYS(2023) + "\AsyncTest.htm"
ERASE (lcFile) 

loIP.HTTPGetExAsync("/wconnect/wc.dll?wwdemo~TestPage",;
                    lcFile,40000,"",10)
loIP.HTTPClose()


*** The following is a simulation of some check code
*** this could be done off a timer or some other processing
*** that took place instead of in this poll loop

lnSeconds = SECONDS()

*** Simulate checking for file
DO WHILE SECONDS() - lnSeconds < 15
  lcResult = File2Var(lcFile)
  ? "Checking...",LEN(lcResult)
  IF EMPTY(lcResult)
     DOEVENTS
     LOOP
  ENDIF

  *** We got our result - let's delete the file
  *** to signal the thread we're done to kill the thread
  ERASE (lcFile)

  EXIT
ENDDO

*** Just display the result as HTML
SHOWHTML(lcResult)

See also:

Class wwHTTP


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