Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 401
Dominik Avatar asked Mar 03 '23 11:03

Dominik


1 Answers

This works perfectly for me

Use

winHttpReq.Option(4) = &H3300

instead of

winHttpReq.Option(4) = 13056
like image 153
p741633 Avatar answered Mar 05 '23 18:03

p741633