证书无效或不正确“WinHttp.WinHttpRequest.5.1”

时间:2015-08-04 14:17:43

标签: vba request winhttp

我正在运行一个调用函数从服务器检索信息的宏。我正在使用“WinHttp.WinHttpRequest.5.1”进行连接。该宏工作正常95%的请求返回有效的结果。但是其他5%导致了以下错误:

运行时错误:授权证书无效或不正确-2147012851(80072f0d)

每当发生此错误时,我都会转到该站点登录,然后从停止的位置执行我的代码。然后导致错误的相同请求返回有效结果

我支持代理。

    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)

知道为什么会发生这种情况或如何处理此错误?

1 个答案:

答案 0 :(得分:0)

关于证书的弹出消息我也有同样的问题。我找到了解决方案,它为我工作。在我的代码中,它看起来像这样:

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

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

该行xmlhttp.option(6) = False关闭了有关证书的消息。