*(00)*

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
我正在使用Server XMLHTTP对象在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 ("")
 
我以前有这个问题一段时间,我只是设法过去了,谢谢:
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 MethodgetOption 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

 

'ASP调用HTTPS完整代码
Function GetHttpPage(furl, charset)
'on error resume next
Dim http
Set http = Server.createobject("Msxml2.ServerXMLHTTP")

'增加此代码,可支持https
http.setOption 2,SXH_SERVER_CERT_IGNORE_ALL_SERVER_ERRORS
http.Open "GET", furl, false
'response.write furl':response.end
http.Send ()
'response.write Err.Description
'response.write ",,,222"&furl&",,,333"&http.readystate
'response.end
If http.readystate<>4 Then
Exit Function
End If
GetHttpPage = BytesToStr(http.ResponseBody, charset)
Set http = Nothing
End function

------------------------------------------------------------------------

'ASP打印错误提示代码示例:
'遇到错误继续执行
on error resume next

'此处为报错语句
'................
'打印错误语句 'response.write Err.Description 'response.end

 

 

 

posted on 2021-01-19 13:41  *(00)*  阅读(582)  评论(0编辑  收藏  举报