【发布时间】:2016-01-21 12:07:16
【问题描述】:
我尝试使用 VBA 从 Excel 中的服务器下载文件。这在使用 HTTP 时工作正常,但在使用 HTTPS 时不起作用。
我可以在 Internet Explorer 中访问这两个地址 (HTTP/HTTPS)。如果我使用带有 HTTP 地址的 URLDownloadToFile 下载文件。
使用HTTPSadress 时,我得到返回码-2146697211。也许这是一个证书问题?
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
Dim Ret As Long
Sub DownloadCode()
Dim strURL As String
Dim strPath As String
strURL = "https:/url.de/module.bas"
strPath = Environ("TEMP") & "\Module.bas"
Ret = URLDownloadToFile(0, strURL, strPath, 0, 0)
If Ret = 0 Then
' MsgBox "File successfully downloaded"
Else
MsgBox "Returncode:" & Ret & " Unable to download Code`enter code here`."
End If
End Sub
【问题讨论】:
-
是的,该 URL 的证书我们仅对 www.fontshop.at 有效,因此请求失败。我不知道有一种方法可以简单地告诉 URLDownloadToFile 忽略证书错误,切换到简单的 XMLHttp,例如VBA ServerXMLHTTP https request with self signed certificate
-
也许这篇文章有帮助? social.msdn.microsoft.com/Forums/ie/en-US/…