Ihidan
Ihidan

Reputation: 568

Certificate not valid or incorrect "WinHttp.WinHttpRequest.5.1"

I am running a macro that calls a function to retrieve information from a server. I am using "WinHttp.WinHttpRequest.5.1" to connect. The macro works fine for 95% of my request return a valid result. But the other 5% caused the following error:

Run time error: authority certificate not valid or incorrect -2147012851(80072f0d)

Whenever this error happens I got go to that site log in, and then execute my code from where it stopped. Then the same request that caused the error returns a valid result

I am behind a proxy.

Set htttpObj = CreateObject("WinHttp.WinHttpRequest.5.1")

url = PrefixoUrl + "/Clientes/ServerToExcel/S2E_001.php?func1=" & func1 & "&func2=" & func2
'time out
htttpObj.SetTimeouts 10000, 10000, 10000, 300000   

'open
If proxyNeeded And authNeeded Then
    htttpObj.Open "POST", url, False, ProxyUser, ProxyPass         
Else
    htttpObj.Open "POST", url, False
End If

'header
htttpObj.setRequestHeader headerName, headerValue

'Proxy IP
If proxyNeeded Then
    htttpObj.setProxy 2, ProxyIp + ":" + ProxyPort
End If

'proxy credentials
If proxyNeeded And authNeeded Then
    HTTPREQUEST_SETCREDENTIALS_FOR_PROXY = 1
    htttpObj.SetCredentials ProxyUser, ProxyPass, HTTPREQUEST_SETCREDENTIALS_FOR_PROXY
End If

'Send
htttpObj.Send ("func1=" & func1 & "&func2=" & func2 & "&username=" & loginSite & "&psd=" & passSite)

Any idea why this is happening or how to handle this error?

Upvotes: 4

Views: 2602

Answers (1)

Teamothy
Teamothy

Reputation: 2016

I had same problem with that pop up message about certificate. I found a solution and it worked for me. In my code it looks like this:

Set xmlhttp = CreateObject("WinHttp.WinHttpRequest.5.1")

xmlhttp.option(6) = False
xmlhttp.Open "GET", url, False
xmlhttp.send

That line xmlhttp.option(6) = False turned this message about certificate off.

Upvotes: 0

Related Questions