VBA | WinHttpRequest.5.1 | Ignore SSL Error doesn't work anymore
Asked Answered
D

1

6

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

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:

runtime error -2147012727 (80072f89) certificate invalid

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

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.

Decerebrate answered 12/5, 2020 at 16:30 Comment(1)
I found out, that the code works fine on an other Windows-PC. Is there a security setting which disable the option to suppress SSL-Errors?Decerebrate
O
10

This works perfectly for me

Use

winHttpReq.Option(4) = &H3300

instead of

winHttpReq.Option(4) = 13056
Orit answered 16/9, 2020 at 3:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.