使用 VBA for Excel 的 HTTPS POST 请求

发布于 2024-07-30 17:11:20 字数 161 浏览 1 评论 0原文

我使用“WinHttp.WinHttpRequest.5.1”从 Excel 中的 VBA 发送 HTTP POST 请求。 但我无法对 HTTPS 执行此操作,因为我收到了 SSL 证书错误。

您将使用什么 VBA 代码来协商从 Excel 中的 VBA 到网站的 SSL 连接?

I use "WinHttp.WinHttpRequest.5.1" to send HTTP POST requests from VBA in Excel.
But I could not manage to do it for HTTPS, as I received an SSL certificate error.

What VBA code would you use to negotiate an SSL connection to a website from VBA in Excel ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

浅紫色的梦幻 2024-08-06 17:11:20

WinHttpRequest 对象有一个 SetClientCertificate 方法。 尝试从 MSDN 获取此代码示例(我尝试将其改编为 VBA):

' Instantiate a WinHttpRequest object. '
Dim HttpReq as new ActiveXObject("WinHttp.WinHttpRequest.5.1")

' Open an HTTP connection. '
HttpReq.Open("GET", "https://www.test.com/", false)

' Select a client certificate. '
HttpReq.SetClientCertificate("LOCAL_MACHINE\Personal\My Certificate")

' Send the HTTP Request. '
HttpReq.Send()

The WinHttpRequest object has a SetClientCertificate method. Try this code example taken from the MSDN (I tried to adapt it for VBA):

' Instantiate a WinHttpRequest object. '
Dim HttpReq as new ActiveXObject("WinHttp.WinHttpRequest.5.1")

' Open an HTTP connection. '
HttpReq.Open("GET", "https://www.test.com/", false)

' Select a client certificate. '
HttpReq.SetClientCertificate("LOCAL_MACHINE\Personal\My Certificate")

' Send the HTTP Request. '
HttpReq.Send()
多情癖 2024-08-06 17:11:20

虽然我没有使用 COM 组件 (WinHttpRequest),但似乎您需要调用 SetClientCertificate 在调用发送之前,按照链接。

这有帮助吗?

While I have not used the COM component (WinHttpRequest), it seems you need a call to SetClientCertificate prior to calling send, as per the link.

Does that help?

提笔落墨 2024-08-06 17:11:20

我有同样的情况(从Excel中的VBA发送http请求); 我创建了三个对象:

Set HttpReq = CreateObject("WinHttp.WinHttpRequest.5.1") 

--用于http请求类,

Set fsobj = CreateObject("Scripting.FileSystemObject")
Set txtobj = fso.OpenTextFile("C:\PKCERT.PEM")

--将证书内容放入变量中,将其传递给HttpReq.SetClientCertificate

certificate_data = txtobj.ReadAll
HttpReq.SetClientCertificate (certificate_content)

这样我就可以发送包含其公钥的请求证书,像往常一样,

HttpReq.Send

PS我在 http://www.808.dk/?code 找到了一个脚本-simplewinhttprequest——在我的情况下效果很好,希望在你的情况下也能正常工作。

I have the same situation (send a http request from a VBA in Excel); I created three objects:

Set HttpReq = CreateObject("WinHttp.WinHttpRequest.5.1") 

-- for the http request class, and

Set fsobj = CreateObject("Scripting.FileSystemObject")
Set txtobj = fso.OpenTextFile("C:\PKCERT.PEM")

-- to get into a variable the certificate contents, to pass it to HttpReq.SetClientCertificate,

certificate_data = txtobj.ReadAll
HttpReq.SetClientCertificate (certificate_content)

So I can send the request including its public key certificate, as usual,

HttpReq.Send

P.S. I found a script at http://www.808.dk/?code-simplewinhttprequest -- it worked fine in my case, hope in yours too.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文