5

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.

Dominik
  • 178
  • 2
  • 8
  • 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? – Dominik May 13 '20 at 07:04

1 Answers1

9

This works perfectly for me

Use

winHttpReq.Option(4) = &H3300

instead of

winHttpReq.Option(4) = 13056
p741633
  • 91
  • 1
  • 2