Proxy authentication required (http error 407) with WinHttpRequest and proxy with integrated Windows authentication and https

二次信任 提交于 2020-06-16 17:08:53

问题


I'm trying to access an external website from my company network using WinHttpRequest from VBA. The company has a proxy server that requires integrated Windows authentication.

The following code works if I try to access a URL with plain http, but I get http status code 407 - proxy authentication required if I try to access a URL with https.

What do I need to do to make the code work with https?

Sub a()
    Dim w As New WinHttp.WinHttpRequest

    'set proxy        
    w.SetProxy 2, "myproxy:8080"
    'use integrated windows authentication
    w.SetAutoLogonPolicy AutoLogonPolicy_Always
    w.Option(WinHttpRequestOption_EnableRedirects) = True
    w.Open "GET", "https://..."
    w.Send
    Debug.Print w.Status ' Status = 407
    Debug.Print w.Option(WinHttpRequestOption_URL)
End Sub

回答1:


Try, please insert (between Open and Send) a line for setting credentials and another one for ignoring (all) SSL errors. Try something lile that:

Sub AccessSiteThroughProxy()
    Dim w As New WinHttp.WinHttpRequest

    'set proxy
    w.setProxy 2, "myproxy:8080"
    'use integrated windows authentication
    w.SetAutoLogonPolicy AutoLogonPolicy_Always
    w.Option(WinHttpRequestOption_EnableRedirects) = True
    w.Open "GET", "https://..."

    'try inserting a line to set credentials:________________________________________
     w.SetCredentials UserName, Password, HTTPREQUEST_SETCREDENTIALS_FOR_SERVER ' try Const HTTPREQUEST_SETCREDENTIALS_FOR_SERVER = 0
     'in order to ignore SSL erors, try:
     w.Option(WinHttpRequestOption_SslErrorIgnoreFlags) = &H3300
    '_________________________________________________________________________________

    w.send
    Debug.Print w.Status ' Status = 407
    Debug.Print w.Option(WinHttpRequestOption_URL)
End Sub


来源:https://stackoverflow.com/questions/61835301/proxy-authentication-required-http-error-407-with-winhttprequest-and-proxy-wit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!