问题
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