Jump to content

WinHttp.au3 Interrupting a POST process in a loop


EKY32
 Share

Recommended Posts

Hello, how should I stop any code running inside a loop? using the best method.

Thanks.

#include "WinHttp.au3"
#include <WindowsConstants.au3>
Global $sDomain = "https://website.com"
Global $sPage = "page.html"


$Form1 = GUICreate("TEST", 328, 178, 192, 124)
$Start = GUICtrlCreateButton("Start", 24, 144, 75, 25)
$Stop = GUICtrlCreateButton("Stop", 224, 144, 75, 25)
$Console = GUICtrlCreateEdit("", 8, 8, 313, 129)
GUISetState(@SW_SHOW)


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
            
        Case $Start
             $hOpen = _WinHttpOpen()
             $hConnect = _WinHttpConnect($hOpen, $sDomain)
             For $i = 1 To 20
                $sReturned = _WinHttpSimpleSSLRequest($hConnect, "POST", $sPage, Default)
                ; Reporting to console
                GUICtrlSetData($Console, GUICtrlRead($Console & @CRLF))
             Next
             
        Case $Stop
            ; Stop the posting process up there ^

    EndSwitch
WEnd


_WinHttpCloseHandle($hConnect)
_WinHttpCloseHandle($hOpen)

[font="'trebuchet ms', helvetica, sans-serif;"]Please mark the answer of your question if you found it.[/font]

Link to comment
Share on other sites

Thank you, I don't want to use a hotkey, how should I handle the cancel code to pass the ExitLoop command while i'm inside that loop?

[font="'trebuchet ms', helvetica, sans-serif;"]Please mark the answer of your question if you found it.[/font]

Link to comment
Share on other sites

  • Moderators

You don't want to use a hotkey?

Okay, so now the question... "What method would you like to use to tell the script to stop looping?"

Edit:

P.S. Not sure yelling at it without code to interpret and a mic is going to work.

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

This stmt results in nothing...

GUICtrlSetData($Console, GUICtrlRead($Console & @CRLF))

You probably want...

GUICtrlSetData($Console, $sReturned & @CRLF, 1)

kylomas

edit: To interrupt your loop you might try something like this...

#include "WinHttp.au3"
#include <WindowsConstants.au3>
Global $sDomain = "https://website.com"
Global $sPage = "page.html"


$Form1 = GUICreate("TEST", 600,500)
$Start = GUICtrlCreateButton("Start", 10, 450, 100, 20)
$Stop = GUICtrlCreateButton("Stop", 150,450,100,20)
$Console = GUICtrlCreateEdit("", 10, 10, 580, 400)
GUISetState(@SW_SHOW)


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case -3
            Exit

        Case $Start
             $hOpen = _WinHttpOpen()
             $hConnect = _WinHttpConnect($hOpen, $sDomain)
             For $i = 1 To 20
                if guigetmsg() = $stop then exitloop    ;   < ------- test for stop control
                $sReturned = _WinHttpSimpleSSLRequest($hConnect, "POST", $sPage, Default)
                ; Reporting to console
                GUICtrlSetData($Console, $sReturned & @CRLF, 1)
             Next

        Case $Stop
            ; Stop the posting process up there ^

    EndSwitch
WEnd


_WinHttpCloseHandle($hConnect)
_WinHttpCloseHandle($hOpen)
Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

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...