通过带有自定义标头的 shdocvw.dll 下载文件 [英] File Download via shdocvw.dll with custom headers

查看:30
本文介绍了通过带有自定义标头的 shdocvw.dll 下载文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要通过 vba 应用程序在 msaccess 中下载一个非常大的文件.

I need to download a really large file in msaccess via a vba application.

使用对象 MSXML2.ServerXMLHTTP.6.0 和 WinHttp.WinHttpRequest.5.1 会导致错误,指出没有足够的可用存储空间来完成此操作.因此我求助于使用 shdocvw.dll 中的 DoFileDownload 方法.我想要做的是将额外的标头(API 密钥)传递给函数发送的请求.

Using the objects MSXML2.ServerXMLHTTP.6.0 and WinHttp.WinHttpRequest.5.1 result in an error stating that there is not enough storage available to complete this operation. Therefore i resorted in using the DoFileDownload method from shdocvw.dll. What i want to do is pass an extra header (an API key) to the request sent by the function.

这大概是我想要做的.

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

我该如何解决这个问题?

How do i approach this problem?

推荐答案

一次下载整个文件的 WebRequest 存储整个数据作为响应.

A WebRequest downloading a whole file at once stores the whole data in response.

虽然有分块响应的选项,但使用 Wget 编码更少,但更多选项.

Although there are options to chunk response, using Wget is less coding, but more options.

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

这篇关于通过带有自定义标头的 shdocvw.dll 下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆