https - 如何使用 VBSCRIPT 并接受所有证书来使用 HTTPS 连接下载文件

标签 https vbscript certificate

我有一个脚本可以从 https://mysite.com/xxx.zip 下载文件但当它转到安全链接时,我想接受证书。这里有一个很大的问题。我无法有效使用“ServicePointManager.ServerCertificateValidationCallback”。

有人可以帮忙吗?

我还有证书网站的域名:*.mysite.com

代码:

Const scriptVer  = "1.0"
Const DownloadDest = "https://mysite.com/xxx.zip"
Const LocalFile = "F:\Testing\xxx.zip"
Const webUser = "admin"
Const webPass = "admin"
Const DownloadType = "binary"
dim strURL

function getit()
  dim xmlhttp

  set xmlhttp=createobject("MSXML2.XMLHTTP.3.0")
  'xmlhttp.SetOption 2, 13056 'If https -> Ignore all SSL errors
  strURL = DownloadDest
  Wscript.Echo "Download-URL: " & strURL

  'For basic auth, use the line below together with user+pass variables above
  xmlhttp.Open "GET", strURL, false, WebUser, WebPass
  'xmlhttp.Open "GET", strURL, false

  xmlhttp.Send
  Wscript.Echo "Download-Status: " & xmlhttp.Status & " " & xmlhttp.statusText

  If xmlhttp.Status = 200 Then
    Dim objStream
    set objStream = CreateObject("ADODB.Stream")
    objStream.Type = 1 'adTypeBinary
    objStream.Open
    objStream.Write xmlhttp.responseBody
    objStream.SaveToFile LocalFile
    objStream.Close
    set objStream = Nothing
  End If


  set xmlhttp=Nothing
End function 

'=======================================================================
' End Function Defs, Start Main
'=======================================================================
' Get cmdline params and initialize variables
If Wscript.Arguments.Named.Exists("h") Then
  Wscript.Echo "Usage: http-download.vbs"
  Wscript.Echo "version " & scriptVer
  WScript.Quit(intOK)
End If

getit()
Wscript.Echo "Download Complete. See " & LocalFile & " for success."
Wscript.Quit(intOK)

ServicePointManager.ServerCertificateValidationCallback = AddressOf AcceptAllCertifications

Private Shared Function ValidateCertificate(sender As Object, certificate As X509Certificate, chain As X509Chain, sslPolicyErrors As SslPolicyErrors) As Boolean
    return True
End Function

最佳答案

ServicePointManager 是一个 .NET 类,因此不能在 VBScript 中使用。试试这个:

Set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP")
xmlhttp.setOption 2, 13056

必须在此处使用MSXML2.ServerXMLHTTP,因为MSXML2.XMLHTTP请求没有setOption方法。

也许你不应该broadcast你的问题。这不太礼貌。

关于https - 如何使用 VBSCRIPT 并接受所有证书来使用 HTTPS 连接下载文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12143787/

相关文章:

python - 无法使用 python HTTPSConnection() 连接到 Web 服务器

用于驱动器映射的 VBA SharePoint 身份验证

c# - 创建由其他 ECDSA 证书签名的 ECDSA 证书

http - 合并两个 nginx 服务器

https - 为什么在ffmpeg中找不到https协议(protocol)?

java - Appengine 上的 Twilio 客户端库

powershell - New-SelfSignedCertificate -CertStoreLocation 找不到路径

javascript - 使用经典 asp 进行 Dreamweaver 回发

vbscript - 通过 VBScript 检测耳机是否插入

Git 克隆在受证书保护的 apache 后面通过 gitlab 故障转移 https