windows vbscript 下载文件(绕过无效证书错误)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5096787/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
vbscript to download a file (bypassing invalid certificate errors)
提问by John
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
Using the above code I'm trying to download a file from a secure site to install a security certificate automatically, it works fine from a http site, but I'm needing to bypass the security errors. Any ideas?
使用上面的代码,我尝试从安全站点下载文件以自动安装安全证书,它在 http 站点上运行良好,但我需要绕过安全错误。有任何想法吗?
回答by jveazey
You need to switch from MSXML2.XMLHTTP to MSXML2.ServerXMLHTTPand use the setOptionmethod with the value SXH_SERVER_CERT_IGNORE_ALL_SERVER_ERRORS. Just place the call between Open and Send. Here's your example updated with the new code.
您需要从 MSXML2.XMLHTTP 切换到MSXML2.ServerXMLHTTP并使用值为SXH_SERVER_CERT_IGNORE_ALL_SERVER_ERRORS的setOption方法。只需在打开和发送之间进行呼叫。这是使用新代码更新的示例。
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