我想使用HTTP下载文件。我该怎么做?
答案 0 :(得分:1)
我对此进行了进一步调查,并在上周重新订购了我的建议:
VO的“Internet”库中的“CHttp”类有一个方法GetFile(the VO 2.5 "what's new" has a brief description on page 10)。不过,我没试过。你可能想要这样的东西:
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.
我认为另一种方法是使用Windows ShellExecute
函数来调用下载文件的外部程序。我找到了ShellExecute here的一个例子。我没试过这个,因为我目前没有可用的VO编译器(或帮助文件!)。我不确定这是否是一个好方法,我不知道是否通过提供一个偷偷摸摸的文件名来试图运行恶意命令的人是安全的。但我认为以下可能有效。它假设您的路径上有程序curl.exe
(请参阅:curl),该程序用于下载文件。您可能需要curl.exe
的完整路径。我不确定默认情况下文件的保存位置(我认为您可以在标有lpDirectory
的参数中指定工作目录)
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)
似乎有一种方法App:Run(cCommand)
可用于启动外部应用程序