Jump to content

winhttp ExitLoop issue


 Share

Recommended Posts

Hi friends, if my $error variable is 1 I want to exit the loop For $m = 0 To UBound($a) - 1 How do I do it?
Thank you

Global $oMyError = ObjEvent("AutoIt.Error", "httperror")
Global $error = 0

Local $a[3] = ["http://127.0.1.1", "http://127.0.0.2", "http://127.0.0.3"]

Local $b[2] = ["Post1Test1", "Post1Test2"]
Local $c[2] = ["Post2Test1", "Post2Test2"]

For $m = 0 To UBound($a) - 1
    For $X = 0 To UBound($b) - 1
        For $i = 0 To UBound($c) - 1
            $con = Connect($a[$m], $b[$X] & $c[$i])
            ConsoleWrite(" Line Connect : " & @ScriptLineNumber & " -> " & $a[$m] & " " & $b[$X] & " " & $c[$i] & @CRLF)
            If $error = 1 Then
                ExitLoop
            EndIf
        Next
    Next
Next

Func Connect($Url, $PostData = '')
    Local $oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
    $oHTTP.Open("POST", $Url, False)
    $oHTTP.SetRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:55.0) Gecko/20100101 Firefox/55.0")
    $oHTTP.SetRequestHeader("Accept-Language", "tr-TR,tr;q=0.8,en-US;q=0.5,en;q=0.3")
    $oHTTP.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded")
    $oHTTP.SetRequestHeader("X-Requested-With", "XMLHttpRequest")
    $oHTTP.Send($PostData)
    If @error Then
        ConsoleWrite("Error connection" & @CRLF)
        $error = 1

        $oHTTP = 0

        Return SetError(1)
    EndIf
    ConsoleWrite(" Line : " & @ScriptLineNumber & " -> Status : " & $oHTTP.Status & @CRLF)
    If $oHTTP.Status = 200 Then
        Local $sReceived = $oHTTP.ResponseText
        $oHTTP = Null
        Return $sReceived
    EndIf

    $oHTTP = Null
    Return -1
EndFunc   ;==>Connect

Func httperror()
    ConsoleWrite("http error" & @CRLF)

    $oMyError.Clear

    Return SetError(1)
EndFunc   ;==>httperror

 

Link to comment
Share on other sites

Get rid of or move the ConsoleWrite before the check of @error

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Yes I checked with ConsoleWrite, but the error value turns to 1 but does not exit the loop

For $m = 0 To UBound($a) - 1
    For $X = 0 To UBound($b) - 1
        For $i = 0 To UBound($c) - 1
            $con = Connect($a[$m], $b[$X] & $c[$i])
            ConsoleWrite(" Line Connect : " & @ScriptLineNumber & " -> " & " Error value " & $error & " " & $a[$m] & " " & $b[$X] & " " & $c[$i] & @CRLF)
            If $error = 1 Then
                ExitLoop
            EndIf
        Next
    Next
Next

 

Link to comment
Share on other sites

The ConsoleWrite is resetting the error condition, so it will never exit the loop. Hence, get rid of it, or move it elsewhere in your script.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

@Danp2 @BrewManNH still no change at all :(

Global $oMyError = ObjEvent("AutoIt.Error", "httperror")
Global $error = 0

Local $a[3] = ["http://127.0.1.1", "http://127.0.0.2", "http://127.0.0.3"]

Local $b[2] = ["Post1Test1", "Post1Test2"]
Local $c[2] = ["Post2Test1", "Post2Test2"]

For $m = 0 To UBound($a) - 1
    For $X = 0 To UBound($b) - 1
        For $i = 0 To UBound($c) - 1
            $con = Connect($a[$m], $b[$X] & $c[$i])
            ConsoleWrite(" Line Connect : " & @ScriptLineNumber & " -> " & " Error value " & $error & " " & $a[$m] & " " & $b[$X] & " " & $c[$i] & @CRLF)
            If $error = 1 Then ExitLoop
        Next
    Next
Next

Func Connect($Url, $PostData = '')
    Local $oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
    $oHTTP.Open("POST", $Url, False)
    $oHTTP.SetRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:55.0) Gecko/20100101 Firefox/55.0")
    $oHTTP.SetRequestHeader("Accept-Language", "tr-TR,tr;q=0.8,en-US;q=0.5,en;q=0.3")
    $oHTTP.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded")
    $oHTTP.SetRequestHeader("X-Requested-With", "XMLHttpRequest")
    $oHTTP.Send($PostData)
    If @error Then
        $error = 1
        $oHTTP = 0
        Return SetError(1)
    EndIf
    If $oHTTP.Status = 200 Then
        Local $sReceived = $oHTTP.ResponseText
        $oHTTP = Null
        Return $sReceived
    EndIf

    $oHTTP = Null
    Return -1
EndFunc   ;==>Connect

Func httperror()
    $oMyError.Clear
    Return SetError(1)
EndFunc   ;==>httperror

 

Edited by youtuber
Link to comment
Share on other sites

For $m = 0 To UBound($a) - 1
    For $X = 0 To UBound($b) - 1
        For $i = 0 To UBound($c) - 1
            $con = Connect($a[$m], $b[$X] & $c[$i])
            $error = @error ; <==============================
            ConsoleWrite(" Line Connect : " & @ScriptLineNumber & " -> " & $a[$m] & " " & $b[$X] & " " & $c[$i] & @CRLF)
            If $error = 1 Then
                ExitLoop
            EndIf
        Next
    Next
Next

 

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

2 hours ago, youtuber said:

if my $error variable is 1 I want to exit the loop For $m = 0 To UBound($a) - 1 How do I do it?

This is what you originally stated. That is the outer-most loop, so the looping stops entirely when you use the code I posted.

If you want that outer loop to continue, then reduce the ExitLoop value by 1.

Link to comment
Share on other sites

@Danp2 Thank you, I think it's true

Global $oMyError = ObjEvent("AutoIt.Error", "httperror")
Global $error = 0

Local $a[5] = ["http://127.0.0.1", "http://127.0.0.2", "http://127.0.0.3", "http://127.0.0.1", "https://www.autoitscript.com"]

Local $b[2] = ["Post1Test1", "Post1Test2"]
Local $c[2] = ["Post2Test1", "Post2Test2"]

For $m = 0 To UBound($a) - 1
    For $X = 0 To UBound($b) - 1
        For $i = 0 To UBound($c) - 1
            $con = Connect($a[$m], $b[$X] & $c[$i])
            $error = @error ; <==============================
            ConsoleWrite(" Line Connect : " & @ScriptLineNumber & " -> " & $a[$m] & " " & $b[$X] & " " & $c[$i] & @CRLF)
            If $error = 1 Then
                ExitLoop 2
            EndIf
        Next
    Next
Next

Func Connect($Url, $PostData = '')
    Local $oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
    $oHTTP.Open("POST", $Url, False)
    $oHTTP.SetRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:55.0) Gecko/20100101 Firefox/55.0")
    $oHTTP.SetRequestHeader("Accept-Language", "tr-TR,tr;q=0.8,en-US;q=0.5,en;q=0.3")
    $oHTTP.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded")
    $oHTTP.SetRequestHeader("X-Requested-With", "XMLHttpRequest")
    $oHTTP.Send($PostData)
    If @error Then
        $error = 1
        $oHTTP = 0
        Return SetError(1)
    EndIf
    If $oHTTP.Status = 200 Then
        Local $sReceived = $oHTTP.ResponseText
        $oHTTP = Null
        Return $sReceived
    EndIf

    $oHTTP = Null
    Return -1
EndFunc   ;==>Connect

Func httperror()
    $oMyError.Clear
    Return SetError(1)
EndFunc   ;==>httperror

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...