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

时间:2011-02-23 20:38:22

标签: windows ssl vbscript https download

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

使用上面的代码我试图从安全站点下载文件以自动安装安全证书,它可以从http站点正常工作,但我需要绕过安全错误。有什么想法吗?

1 个答案:

答案 0 :(得分:4)

您需要从MSXML2.XMLHTTP切换到MSXML2.ServerXMLHTTP并使用值setOptionSXH_SERVER_CERT_IGNORE_ALL_SERVER_ERRORS方法。只需在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