我正在使用ServerXMLHTTP对象在excel 2007 vba脚本上发出一些http请求。
但我需要连接到使用自签名SSL证书的https服务器,因此默认情况下我收到消息“证书颁发机构无效或不正确”。有没有办法配置ServerXMLHTTP对象,使其不需要CA证书?
以下是一些示例代码:
Set objHTTP = CreateObject("MSXML2.ServerXMLHTTP")
objHTTP.Open "POST", "https://invernalia.homelinux.net", False, "user", "password"
objHTTP.setRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"
objHTTP.send ("")
答案 0 :(得分:27)
我曾经有过这个问题已经有一段时间了,而且我只是设法克服了这个问题:
Set objHTTP = CreateObject("MSXML2.ServerXMLHTTP")
objHTTP.SetOption(2, objHTTP.GetOption(2) - SXH_SERVER_CERT_IGNORE_ALL_SERVER_ERRORS)
objHTTP.Open "POST", "https://invernalia.homelinux.net", False, "user", "password"
objHTTP.setRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"
objHTTP.send ("")
我在setOption Method和getOption Method
找到了这个在此代码中,我刚刚使用了SXH_SERVER_CERT_IGNORE_ALL_SERVER_ERRORS
,但您可以尝试更具体的其他代码:
SXH_SERVER_CERT_IGNORE_WRONG_USAGE
SXH_SERVER_CERT_IGNORE_CERT_CN_INVALID
SXH_SERVER_CERT_IGNORE_CERT_DATE_INVALID
SXH_SERVER_CERT_IGNORE_UNKNOWN_CA
答案 1 :(得分:6)
Set objHTTP = CreateObject("MSXML2.ServerXMLHTTP")
objHTTP.SetOption(2, objHTTP.GetOption(2) - SXH_SERVER_CERT_IGNORE_ALL_SERVER_ERRORS)
objHTTP.Open "POST", "https://invernalia.homelinux.net", False, "user", "password"
objHTTP.setRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"
objHTTP.send ("")
通过上述解决方案进行微小改动。而不是:
objHTTP.SetOption(2, objHTTP.GetOption(2) - SXH_SERVER_CERT_IGNORE_ALL_SERVER_ERRORS)
我用过:
objHTTP.SetOption(2) = (objHTTP.GetOption(2) - SXH_SERVER_CERT_IGNORE_ALL_SERVER_ERRORS)
否则我收到错误:
Microsoft VBScript编译错误'800a0414'无法使用括号 调用Sub objHTTP.SetOption时(2,objHTTP.GetOption(2) - SXH_SERVER_CERT_IGNORE_ALL_SERVER_ERRORS)