I'm using code essentially like this to download an XML file:
The call to HttpSendRequest can take a long time, especially when the server it's trying to connect to isn't responding (eg: when it's very busy). In the mean time, VFP is completely unresponsive, and looks like it hung up. (it won't minimize, or redraw itself as other windows are moved in front of it)
Anyone have any ideas on how to give better feedback to the user during a simple HTTP download (with user/pwd authentication)?
- Bill
Get the best answers to your questions -- See FAQ481-4875.
Code:
lhInternetSession = InternetOpen( lcAgent, INTERNET_OPEN_TYPE_PRECONFIG, '', '', SYNCHRONOUS )
InternetSetOption( lhInternetSession, INTERNET_OPTION_USERNAME, @lcUser, len(lcUser) )
InternetSetOption( lhInternetSession, INTERNET_OPTION_PASSWORD, @lcPwd, len(lcPwd) )
lhConnect = InternetConnect( lhInternetSession, lcHost, 0, lcUser, lcPwd, INTERNET_SERVICE_HTTP, 0, 0 )
lhUrlFile = HttpOpenRequest( lhConnect, 'GET', lcObj, 0, 0, 0, ;
bitor( INTERNET_FLAG_KEEP_CONNECTION, INTERNET_FLAG_RELOAD ), 0 )
lnRet = HttpSendRequest( lhUrlFile, 0, 0, 0, 0 )
DO WHILE llOK and NOT llCancel
* set aside a big buffer
lcReadBuffer = SPACE(10000)
lnBytesRead = 0
lnOK = InternetReadFile( lhUrlFile, @lcReadBuffer, LEN(lcReadBuffer), @lnBytesRead)
if ( lnBytesRead > 0 )
if type('pcOptOutputFile')='C'
StrToFile(left(lcReadBuffer,lnBytesRead),pcOptOutputFile,.T.) && Add to file.
else
lcRetVal = lcRetVal + left( lcReadBuffer, lnBytesRead )
endif
endif
* error trap - either a read failure or read past eof()
llOk = ( lnOK = 1 ) and ( lnBytesRead > 0 )
lnBytesAvail = 0
lnRes1 = 0
lnRes2 = 0
lnOk = InternetQueryDataAvailable( lhUrlFile, @lnBytesAvail, @lnRes1, @lnRes2 )
ENDDO
The call to HttpSendRequest can take a long time, especially when the server it's trying to connect to isn't responding (eg: when it's very busy). In the mean time, VFP is completely unresponsive, and looks like it hung up. (it won't minimize, or redraw itself as other windows are moved in front of it)
Anyone have any ideas on how to give better feedback to the user during a simple HTTP download (with user/pwd authentication)?
- Bill
Get the best answers to your questions -- See FAQ481-4875.