Ariff Posted May 28, 2011 Posted May 28, 2011 Hello everyone, about 2 months ago i read something about AutoIt, since i didnt heard about it yet, i went to check it out and since than im hooked to this amazing scripting/programming language. Ive been experimenting around with it a lot, but today i got stuck on something probably very silly but i cant seem to sort it out. I'll trie to explain : Im trying to automate a login sequence for a website. It consists of sending a POST request with username and password, the server will reply with a basic html page, with a cookie thats being set for the session. I wrote a global function in my script which fills up a string $sRecv with the received data using a do / until loop. This works fine. Do $sRecv &= TCPRecv( $iSocket, 4096 ) Until StringInstr( $sRecv, "</html>" ) The easiest way i thought to leave the loop is when the string "</html>" is received, stating that the received page is at the end and the script can continue. Again this works fine. Next i extract the needed data from $sRecv and use this to create a GET request packet and send it to the server. The server reply's again, but this time without an attached <html> page. Clearly the Do / Until loop is waiting for it, and keeps on looping because the only thing the server sends back is a header without anything else. So i need to add another condition as to when the Do/Until loop can exit and thats where i'm stuck. an example : Do $sRecv &= TCPRecv( $iSocket, 4096 ) Until StringInStr( $sRecv, "</html>" ) Or StringInStr( $sRecv, ??????? ) How can i make the loop exit when its being called the second time so the script can continue ? I tried adding "Or StringInStr( $sRecv, @CRLF & @CRLF ) but this is so common, that the first packet which returns the </html> code never gets received untill the end, because the @CRLF & @CRLF code is found in there a lot of times aswell. Im wondering if i could do some sort of timer 'event' so the do/until loop will exit when there's no data being received anymore for lets say a second. Anyone has another idea on how i can manage this ? I hope you guys understood, since im not a native english speaker. kind regards, Ariff
Wiggyboy Posted June 8, 2011 Posted June 8, 2011 (edited) Umm, if i understood u correctly ur script could look something like this... $WT = 1 While $WT = 1 ;loop this untill $WT is 1 $sRecv &= TCPRecv( $iSocket, 4096 ) ;recive data If $sRecv <> "" Then ;check if we got any data If StringInstr( $sRecv, "</html>" ) Then ;TCPSend($socket,$logindata) Else ;what u wanna do (this will be when u get a pachage back after the logindata) $WT = 0 ;ending the loop!!! EndIf endif WEnd Edited June 8, 2011 by Wiggyboy
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now