背景:
使用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