Two days of searching ant testing and I've compiled from everything I found, small function that is really BIG!
I wanna share it with us, maybe it will be useful for somebody!
I 've prepared working example with this function. Test and have fun!
Code: Select all
PROCEDURE DownloadFromWWW
param cURL, cLocalFileName
LOCAL oCon, oUrl, i
cLocalFileName := alltrim(cLocalFileName)
oUrl := tURL():New( cUrl )
IF Empty( oUrl )
MsgBox("Invalid url " + cUrl)
return
ENDIF
IF oUrl:cProto != "http"
MsgBox('This is a header test for http. Use an http address.')
return
END
oCon := TipClientHttp():New( oUrl )
oCon:nConnTimeout := 20000
MsgBox("Connecting with "+ oUrl:cServer)
IF oCon:Open( cUrl )
MsgBox("Connection eshtablished." +chr(10)+"Press OK to retrieve" + oUrl:cPath +oUrl:cFile)
oCon:WriteAll(cLocalFileName)
MsgBox("Downloaded...")
oCon:Close()
ELSE
MsgBox("Can't connect with "+ oUrl:cServer)
IF oCon:SocketCon == NIL
MsgBox("Connection not initiated")
ELSEIF hb_InetErrorCode( oCon:SocketCon ) == 0
MsgBox("Server sayed: "+ oCon:cReply)
ELSE
MsgBox("Error in connection: " + hb_InetErrorDesc( oCon:SocketCon ))
ENDIF
END
RETURN