vba - 通过带有自定义标头的 shdocvw.dll 下载文件
问题描述
我需要通过 vba 应用程序在 msaccess 中下载一个非常大的文件。
使用对象 MSXML2.ServerXMLHTTP.6.0 和 WinHttp.WinHttpRequest.5.1 会导致错误,指出没有足够的可用存储空间来完成此操作。因此,我使用了来自 shdocvw.dll 的 DoFileDownload 方法。我想要做的是将额外的标头(API 密钥)传递给函数发送的请求。
这大致是我想要做的。
Private Declare Function DoFileDownload Lib "shdocvw.dll" _
(ByVal lpszFile As String) As Long
Public Sub Download()
sDownloadFile = StrConv(<link_to_download>, vbUnicode)
'set a header before calling DoFileDownload
Call DoFileDownload(sDownloadFile)
End Sub
我该如何解决这个问题?
解决方案
一次下载整个文件的 WebRequest 会存储整个数据作为响应。
虽然有分块响应的选项,但使用Wget是更少的编码,而是更多的选项。
Private Sub DownloadFileWget()
Const PathToWget As String = "" 'if wget is not in path use "Path\To\Wget"
Dim LinkToFile As String
Dim SavePath As String
With CreateObject("WScript.Shell")
LinkToFile = "http://download.windowsupdate.com/microsoftupdate/v6/wsusscan/wsusscn2.cab" 'huge file > 500MB
SavePath = "C:\doc" 'folder to save download
.CurrentDirectory = SavePath
.Run Chr(34) & PathToWget & "wget.exe" & Chr(34) & " --header='name: value' " & Chr(34) & LinkToFile & Chr(34) & " -N", 1, True
' -N: Continue download only if the local version is outdated.
End With
End Sub
推荐阅读
- php - 如何在 sql 中使用 LIKE IN 之类的东西?
- angular - 在使用 Angular 6 加载数据时显示表单的策略
- c# - C# DirectorySearcher 只定位服务器所在国家的用户
- jmeter - 使用吞吐量整形计时器
- java - 执行时 Netbeans JavaSE 组件大小不同
- amazon-web-services - S3跨账户访问涉及3个账户
- wso2 - WSO2 ESB 6.1.0 批处理
- node.js - 服务器端的 SuperCluster
- computer-vision - 读取激光雷达数据
- python - 使用 scapy 嗅探 http 数据包