如果您只想使用代码(没有Internet传输控制),VBNet.mvps.org有一篇非常好的使用URLDownloadToFile API调用的how-to文章.
来自文章:
URLDownloadToFile API适用于所有版本的Windows操作系统(Win3,WinNT3.x除外).通过传递远程文件名和本地文件路径和名称,API将下载指定文件的位,并将其保存为目标名称.该函数适用于所有文件类型 - 纯文本,图像,html,mpg,wav和zip文件等,无需修改例程或关注正在下载的文件,也没有任何明显的大小限制或限制.
Private Declare Function URLDownloadToFile Lib "urlmon" _
Alias "URLDownloadToFileA" _
(ByVal pCaller As Long, _
ByVal szURL As String, _
ByVal szFileName As String, _
ByVal dwReserved As Long, _
ByVal lpfnCB As Long) As Long
Private Const ERROR_SUCCESS As Long = 0
Private Const BINDF_GETNEWESTVERSION As Long = &H10
Private Const INTERNET_FLAG_RELOAD As Long = &H80000000
Public Function DownloadFile(sSourceUrl As String, _
sLocalFile As String) As Boolean
//'Download the file. BINDF_GETNEWESTVERSION forces
//'the API to download from the specified source.
//'Passing 0& as dwReserved causes the locally-cached
//'copy to be downloaded, if available. If the API
//'returns ERROR_SUCCESS (0), DownloadFile returns True.
DownloadFile = URLDownloadToFile(0&, _
sSourceUrl, _
sLocalFile, _
BINDF_GETNEWESTVERSION, _
0&) = ERROR_SUCCESS
End Function
Run Code Online (Sandbox Code Playgroud)
仅供参考 - 在Windows 7上进行测试时,它只会返回缓存版本,因此我必须先使用文章中提到的额外功能来清除它(并且可以正常工作).
Private Declare Function DeleteUrlCacheEntry Lib "Wininet.dll" _
Alias "DeleteUrlCacheEntryA" _
(ByVal lpszUrlName As String) As Long
Run Code Online (Sandbox Code Playgroud)
然后,首先使用目标URL调用上述函数,以清除缓存.