Sign in to follow this  
Followers 0
Dirk Diggler

InetGet through proxy doesn't work

6 posts in this topic

I have some workstations in my LAN, and i want to test if some sites is alive. But InetGET doesn't work. I use such script to test it:

HttpSetProxy (2, "192.168.100.1:3128" , "avv", "shaolin" )
InetGet("http://www.mozilla.org",'c:\foo.html')
MsgBox(262144,'Debug line ~' & @ScriptLineNumber,'Selection:' & @lf & 'InetGet("http://www.mozilla.org","c:\foo.html")' & @lf & @lf & 'Return:' & @lf & InetGet("http://www.mozilla.org",'c:\foo.html') & @lf & @lf & '@Error:' & @lf & @Error) ;### Debug MSGBOX
InetGet("http://tega.ru/dirk/download.html")
MsgBox(262144,'Debug line ~' & @ScriptLineNumber,'Selection:' & @lf & 'InetGet("http://tega.ru/dirk/download.html")' & @lf & @lf & 'Return:' & @lf & InetGet("http://tega.ru/dirk/download.html") & @lf & @lf & '@Error:' & @lf & @Error) ;### Debug MSGBOX

I'm ABSOLUTELY sure that proxy address, port, username and password is correct - proxy is installed and configured by me, and I every day use my credentials to surf the net. But, first MsgBox shows me

Return: 0

@error: 10

second:

Return: 0

@error: 0

what's a problem? how to test outer hosts?

Share this post


Link to post
Share on other sites



up

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

As per the help file: only CERN proxy servers are supported. I suspect your proxy does not adhere to CERN standards. Neither does mine. :rolleyes:

However, Microsoft provides the nifty WinHttp.WinHttpRequest.5.1 object, which does the job nicely. The following works just fine on my network, and works in both Integrated Security and non Integrated Security modes. I prefer the Integrated Security mode, as I don't like to put passwords in unencrypted files if I can help it.

;set parameters for using 
Global $UseIntegratedSecurity = False
Global $ProxyServer = "10.0.0.1:8080"
Global $ProxyUser = "username" ;if $UseIntegratedSecurity is true (and working), these can be blank
Global $ProxyPass = "password"

;create WinHttpRequest object for downloading config info
Global $oHttp = ObjCreate ("WinHttp.WinHttpRequest.5.1")
$oHttp.SetProxy(2,$ProxyServer) ; PRECONFIG = 0 (default), DIRECT = 1, PROXY = 2

$sHTML = httpget("http://www.google.com")
ConsoleWrite($sHTML & @CRLF)

func httpget($url)
    $COMerrnotify = false
    
    If $UseIntegratedSecurity Then
        $oHttp.SetAutoLogonPolicy(0) ; Always = 0, OnlyIfBypassProxy = 1, Never = 2
    Else
        $oHttp.SetAutoLogonPolicy(2) ; Always = 0, OnlyIfBypassProxy = 1, Never = 2
    EndIf
    
    $status = $oHttp.Open("GET", $url,false)
    
    If Not $UseIntegratedSecurity Then
        $oHttp.SetCredentials($ProxyUser,$ProxyPass,0) ; HTTPREQUEST_SETCREDENTIALS_FOR_SERVER = 0
    EndIf
    
    
    $oHttp.Send()
    if $oHttp.Status <> "200" then
        $status = $oHttp.Status
        $StatusText = $oHttp.StatusText
        Consolewrite("Status: " & $status & @crlf)
        Consolewrite("StatusText: " & $StatusText & @crlf)
        $COMerrnotify = true
        SetError(1)
        return $status & " - " & $StatusText        
    Else
        $COMerrnotify = true
        SetError(0)
        Consolewrite("Response Headers: " & $oHttp.GetAllResponseHeaders & @crlf)
        return $oHttp.ResponseText
    EndIf
    
EndFunc

;_IEErrorHandlerRegister("ComErrFunc")
$oIEErrorHandler = ObjEvent("AutoIt.Error","ComErrFunc")
global $COMerrnotify = true
Func ComErrFunc()
    If IsObj($oIEErrorHandler) Then
        if $COMerrnotify then
            ConsoleWrite("--> ComErrFunc: COM Error Encountered in " & @ScriptName & @CR)
            ConsoleWrite("----> Scriptline = " & $oIEErrorHandler.scriptline & @CR)
            ConsoleWrite("----> Number Hex = " & Hex($oIEErrorHandler.number, 8) & @CR)
            ConsoleWrite("----> Number = " & $oIEErrorHandler.number & @CR)
            ConsoleWrite("----> Win Description = " & StringStripWS($oIEErrorHandler.WinDescription, 2) & @CR)
            ConsoleWrite("----> Description = " & StringStripWS($oIEErrorHandler.description, 2) & @CR)
            ConsoleWrite("----> Source = " & $oIEErrorHandler.Source & @CR)
            ConsoleWrite("----> Help File = " & $oIEErrorHandler.HelpFile & @CR)
            ConsoleWrite("----> Help Context = " & $oIEErrorHandler.HelpContext & @CR)
            ConsoleWrite("----> Last Dll Error = " & $oIEErrorHandler.LastDllError & @crlf)
        EndIf
        $HexNumber = Hex($oIEErrorHandler.number, 8)
        SetError($HexNumber)
    Else
        SetError(1)
    EndIf
    Return 0
EndFunc
Edited by lod3n

[font="Fixedsys"][list][*]All of my AutoIt Example Scripts[*]http://saneasylum.com[/list][/font]

Share this post


Link to post
Share on other sites

thanks lod3n, this works for me..

Share this post


Link to post
Share on other sites

*nothing to do with the topic*

HAHA, Dirk Diggler...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0