vbscript下载文件(使用https绕过无效的证书错误)

背景:

使用Https从安全站点下载文件来自动安装安全证书,同样的代码可以从http站点正常工作,但目前需要绕过安全错误。

dim xHttp: Set xHttp = createobject("microsoft.xmlhttp")
dim bStrm: Set bStrm = createobject("Adodb.Stream")
xHttp.Open "GET", "https://www.website.com/apps/CertMgr.Exe", False
xHttp.Send
with bStrm
    .type = 1 '//binary
    .open
    .write xHttp.responseBody
    .savetofile "c:\CertMgr.Exe", 2 '//overwrite
end with

方法:

您需要从MSXML2.XMLHTTP切换到MSXML2.ServerXMLHTTP并使用值为SXH_SERVER_CERT_IGNORE_ALL_SERVER_ERRORS的setOption方法。只需在Open和Send之间进行调用即可。这是使用新代码更新的示例。

# 这里需要定义一个常量
const SXH_SERVER_CERT_IGNORE_ALL_SERVER_ERRORS = 13056

dim xHttp: Set xHttp = createobject("MSXML2.ServerXMLHTTP")
dim bStrm: Set bStrm = createobject("Adodb.Stream")
xHttp.Open "GET", "https://www.website.com/apps/CertMgr.Exe", False

# 在这里添加调用
xHttp.setOption 2, SXH_SERVER_CERT_IGNORE_ALL_SERVER_ERRORS

xHttp.Send
with bStrm
    .type = 1 '//binary
    .open
    .write xHttp.responseBody
    .savetofile "c:\CertMgr.Exe", 2 '//overwrite
end with

参考资料:
1、https://oomake.com/question/1249856 20200609
2、http://www.uwenku.com/question/p-uwfnqlxm-tx.html 20200609

猜你喜欢

转载自blog.csdn.net/JohinieLi/article/details/106640169