WinHttpRequest speichert Credentials für Proxyserver

  • Excel

Es gibt 1 Antwort in diesem Thema. Der letzte Beitrag () ist von INOPIAE.

    WinHttpRequest speichert Credentials für Proxyserver

    Hallo Zusammen,

    folgenden Code habe ich mir testweise geschrieben um per VBA den HTML Quellcode einer Webseite auswerten zu können:

    Visual Basic-Quellcode

    1. Option Explicit
    2. Private Const HTTPREQUEST_PROXYSETTING_DEFAULT = 0 '// Default proxy setting. Equivalent to HTTPREQUEST_PROXYSETTING_PRECONFIG.
    3. Private Const HTTPREQUEST_PROXYSETTING_PRECONFIG = 0 '// Indicates that the proxy settings should be obtained from the registry. This assumes that Proxycfg.exe has been run. If Proxycfg.exe has not been run and HTTPREQUEST_PROXYSETTING_PRECONFIG is specified, then the behavior is equivalent to HTTPREQUEST_PROXYSETTING_DIRECT.
    4. Private Const HTTPREQUEST_PROXYSETTING_DIRECT = 1 '// Indicates that all HTTP and HTTPS servers should be accessed directly. Use this command if there is no proxy server.
    5. Private Const HTTPREQUEST_PROXYSETTING_PROXY = 2 '// When HTTPREQUEST_PROXYSETTING_PROXY is specified, varProxyServer should be set to a proxy server string and varBypassList should be set to a domain bypass list string. This proxy configuration applies only to the current instance of the WinHttpRequest object.
    6. Private Const CREDENTIALS_FOR_SERVER = 0
    7. Private Const CREDENTIALS_FOR_PROXY = 1
    8. Public Function GetInnerHtmlBody(ByVal Url As String) As HTMLDocument
    9. Dim ResponseDocument As New HTMLDocument
    10. Dim MyRequest As New WinHttpRequest
    11. With MyRequest
    12. .SetTimeouts 5000, 5000, 5000, 5000
    13. .SetProxy HTTPREQUEST_PROXYSETTING_PROXY, "<PROXY_SERVER_IP>:<PORT>", "*.domain.com"
    14. .Open "GET", Url, False
    15. '// Authentication for the proxy server
    16. '.SetCredentials "<USERNAME>", "<PASSWORD>", CREDENTIALS_FOR_PROXY
    17. .Send
    18. '// Debug
    19. MsgBox .ResponseText, vbInformation, .StatusText & " - " & .Status
    20. ResponseDocument.body.innerHTML = .ResponseText
    21. End With
    22. Set GetInnerHtmlBody = ResponseDocument
    23. End Function

    Wie man sieht ist die Zeile 12. .SetCredentials auskommentiert. Diese wird benötigt um sich über einen Proxyserver mit dem Internet zu verbinden. In meinem Fall ist der Proxyserver zwingen erforderlich.
    "Normal" ist der Zugriff über den Proxyserver im Internetexplorer vorkonfiguriert. (IE -> Einstellungen -> Verbindung -> LAN -> Script -> *.pac Datei)

    Die Einstellungen im IE werden allerdings von Excel VBA ignoriert, da ich am Anfang ohne die 12. Zeile .SetCredentials nur Authorization Required als Result zurück bekam.

    Die Frage:
    • Ich benötigte die Zeile 12. nur genau 1x um mich am Proxyserver zu authentifizieren, alle nachfolgenden Verbindungsversuche mit auskommentierter 12. Zeile funktionierten!
    • Ergo müssen die Credentials gespeichert worden sein, nur wo?
    Was ich bisher kontrolliert habe:
    • Die Zugangsdaten wurden nicht in Windows gespeichert (cmdkey /list = Leer)
    • Die Zugangsdaten wurden nicht als Coockie o.ä. im IE gespeichert (Cache geleert)
    • Die Zugangsdaten bleiben selbst nach mehreren Tagen erhalten (mehrere Neustarts vom Rechner)

    Wo könnten die Daten (Benutzername & Passwort) sonst noch gespeichert worden sein? Evtl. am Proxyserver (glaub ich eher nicht aber naja)?

    Gruß, FireEmerald


    Verweise - VBAProject:
    - Microsoft WinHTTP Services, version 5.1 (C:\Windows\system32\winhttp.dll)
    - Microsoft HTML Object Library (C:\Windows\SysWOW64\mshtml.tlb)

    Microsoft Excel 2010

    Dieser Beitrag wurde bereits 3 mal editiert, zuletzt von „FireEmerald“ ()