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.
This functionality has been deprecated. It still works f
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 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.
While the thread is active (ie. the file still exists or tnSecondsBeforeDelete is not up) the threads resources are not released. This means if you fail to set tnSecondsBeforeDelete and you don't delete the file your application will continue to add more memory for each async operation you call. If you do this in a loop your application will act as if it has a memory leak. Therefore: Be sure you either delete the file or you set the timeout for only a short period to ensure resources for the async thread are deleted.
If you display the result file or otherwise need to save the the downloaded data it's recommended you copy it to a new location or a string and then delete the original to ensure resources are released and your file is not automatically deleted.
If you quit Visual FoxPro while an async thread is active, VFP will crash!
Example
DO wwhttp
loIP = CREATEOBJECT("wwHTTP")
loIP.lSecureLink = .T. && https request
loIP.HTTPConnect("www.west-wind.com")
* ** Post some data
loIP.AddPostkey("FirstName","Rick")
loIP.AddPostkey("Company",TIME())
loIP.AddPostKey("LastName","STRAHL")
* ** file to capture in
lcFile = SYS(2023) + "\AsyncTest.htm"
ERASE (lcFile)
*** Link to retrieve, file to capture to, 40k size, 10 sec timeout
loIP.HTTPGetExAsync("/wconnect/testpage.wwd",;
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
See also:
West Wind Web Connection© West Wind Technologies, 2023 • Updated: 09/29/21
Comment or report problem with topic