带有自签名证书的 VBA ServerXMLHTTP https 请求 [英] VBA ServerXMLHTTP https request with self signed certificate

查看:56
本文介绍了带有自签名证书的 VBA ServerXMLHTTP https 请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 ServerXMLHTTP 对象在 excel 2007 vba 脚本上发出一些 http 请求.

I'm using a ServerXMLHTTP object to make some http requests on an excel 2007 vba script.

但我需要连接到使用自签名 SSL 证书的 https 服务器,因此默认情况下我收到消息证书颁发机构无效或不正确".有没有办法配置 ServerXMLHTTP 对象,使其不需要 CA 证书?

But I need to connect to an https server which uses a self-signed SSL Certificate, so by default I get the message "The certificate authority is invalid or incorrect". Is there a way to configure the ServerXMLHTTP object so that it doesn't requires a CA Certificate?

一些示例代码如下:

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 ("")

推荐答案

这个问题我曾经有一段时间遇到过,多亏了这个,我才得以解决:

I used to have this problem for a while, and I only managed to get past it thanks to this:

Set objHTTP = CreateObject("MSXML2.ServerXMLHTTP")
objHTTP.SetOption 2, objHTTP.GetOption(2)
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 方法getOption方法

I have found this here setOption Method and getOption Method

在此代码中,我刚刚使用了 SXH_SERVER_CERT_IGNORE_ALL_SERVER_ERRORS,但您可以尝试使用更具体的其他代码:

Here in this code I have just used SXH_SERVER_CERT_IGNORE_ALL_SERVER_ERRORS but you can try with others more specific:

  • 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

这篇关于带有自签名证书的 VBA ServerXMLHTTP https 请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆