我在 Windows 7 中安装了三个客户端证书,需要使用一个特定的证书来验证使用 VBA 的 ServerXMLHTTP60 调用。
使用证书的友好名称调用 ServerXMLHTTP60.SetOption 将无错误返回。但是随后的 .send 失败并显示“需要证书才能完成客户端身份验证”。
代码示例:
Public Sub TestCert()
Dim myHTTP as New ServerXMLHTTP60
Dim myURL as String
' Open the connection to the secure server
myHTTP.Open "GET", "https://server/finalpath", False
' Attempt to set the correct client certificate
' I have also tried just the friendly name as well as
' LOCAL_MACHINE\My\cert friendly name'
myHTTP.SetOption 3, "CURRENT_USER\My\cert friendly name"
' Send request fails with "A certificate is required ..."
myHTTP.Send
End Sub
指定的证书通过 IE 或 Firefox 与此站点正常工作。我一定是为证书使用了不正确的路径名。有没有办法确定正确的客户端证书路径名以确保成功?
最佳答案
这让我发疯了几天,但是...... 假设您将客户端安装到当前用户下的默认存储并且您的证书主题为 cn=mycert 那么这似乎可行。运行office16、windows 10、winhttp5.1
Dim apiConnection As New WinHttp.WinHttpRequest
' Set the authentication settings
apiConnection.SetClientCertificate "mycert"
apiConnection.Open "Get", "https://localhost:8443", False
apiConnection.Send
关于vba - 为 ServerXMLHTTP.SetOption 识别正确的客户端证书,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31942165/