I'd like to download a file using HTTP. How do I do it?
1 Answers
I have investigated this further and have re-ordered my suggestions from last week as a result:
The class 'CHttp' in VO's 'Internet' library has a method GetFile (the VO 2.5 "what's new" has a brief description on page 10). I've not tried it, though. You'll probably want something like this:
local oSession as CHttp local lSuccess as logic oSession := CHttp{} oSession:ConnectRemote("foo.example.com") // Server domain name lSuccess := oSession:GetFile("bar/baz.pdf",; // Remote filename "c:\temp\baz.pdf",; // Local filename lFailIfAlreadyExists) oSession:CloseRemote() // If lSuccess, the file should be downloaded to cLocalFileName. // I don't know whether the filename arguments should use / or \ for directory separators.
I think another way is to use the Windows
ShellExecute
function to invoke an external program which downloads the file. I found an example of ShellExecute here. I haven't tried this as I don't have a VO compiler (or help file!) available to me at the moment. I'm not sure whether this is a good way or not, and I don't know whether it's safe from people trying to run a malicious command by supplying a sneaky filename. But I think the following might work. It assumes you have the programcurl.exe
(see: curl) on your path, which is used for downloading the file. You may need the fully path ofcurl.exe
instead. I'm not sure where the file will be saved by default (I think you can specify a working directory in the parameter labelledlpDirectory
)local cParameters as string local cURL:="http://www.example.com/interesting.htm" as string local cLocalFile:="savefile.html" as string cParameters := "-o "+cLocalFile+" "+cURL ShellExecute(NULL /*Window handle*/,; String2PSZ("open"),; String2PSZ("curl.exe"),; String2PSZ(cParameters),; NULL_PTR /* lpDirectory */,; SW_SHOWNORMAL)
See also the MSDN page for ShellExecute.
There appears to be a method
App:Run(cCommand)
which can be used to start external applications

- 1,187
- 10
- 13