VBA |WinHttpRequest.5.1 |忽略SSL错误不再起作用 [英] VBA | WinHttpRequest.5.1 | Ignore SSL Error doesn't work anymore

查看:180
本文介绍了VBA |WinHttpRequest.5.1 |忽略SSL错误不再起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用WinHttpRequest.5.1对象在excel 365(16.0.11328.20562)vba脚本上发出一些https请求.

I'm using a WinHttpRequest.5.1 object to make some https requests on an excel 365 (16.0.11328.20562) vba script.

我知道来自服务器的证书将发生错误,因为CN错误.因此,我通过忽略ssl错误的选项来抑制此错误.

I know that the certificate from server will occurs an error because the CN is wrong. Therefore I suppress this error with the option to ignore ssl errors.

我发誓以下两个星期前工作的代码,现在抛出此错误:

I swear the following code worked two weeks ago and now it throws this error:

运行时错误-2147012727(80072f89)证书无效

下面是代码(包括:Microsoft WinHTTP Services,版本5.1 [winhttpcom.dll]):

Here is the code (included: Microsoft WinHTTP Services, version 5.1 [winhttpcom.dll]):

Sub test()

   Dim url As String
   url = "https://someserver:5096/api/v1/$metadata"

   Dim winHttpReq As WinHttpRequest
   Set winHttpReq = CreateObject("WinHttp.WinHttpRequest.5.1")

   'Ignoriere SSL-Errors
   winHttpReq.Option(4) = 13056

   'I also tested
   'winHttpReq.Option(WinHttpRequestOption_SslErrorIgnoreFlags) = SslErrorFlag_Ignore_All
   'winHttpReq.Option(WinHttpRequestOption_SslErrorIgnoreFlags) = SslErrorFlag_CertCNInvalid

   winHttpReq.Open "GET", url, False

   winHttpReq.Send ("")

   Debug.Print winHttpReq.ResponseText

End Sub

我不明白为什么会收到证书无效错误,尽管应该忽略ssl错误.

I don't understand why I get an certificate invalid error, although ssl-errors should be ignored.

希望您知道为什么会这样,并在此先感谢您的答复.

I hope you know why this happens and thank you in advance for your answers.

推荐答案

这对我来说很完美

使用

winHttpReq.Option(4) = &H3300

代替

winHttpReq.Option(4) = 13056

这篇关于VBA |WinHttpRequest.5.1 |忽略SSL错误不再起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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