Jump to content

Error with winhttp '.ResponseText'


Recommended Posts

How can i handle this Error so my script does not get stuck?

(I think it happens when the request is timed out or there is no internet!)

---------------------------
AutoIt Error
---------------------------
Line 37  (File "C:\Users\Hamid-LT\Desktop\act\BS\BS.au3"):

If @error Or StringLen(.ResponseText) < 500 Then ContinueLoop
If @error Or StringLen(^ ERROR

Error: The requested action with this object has failed.
---------------------------
OK   
---------------------------

Here's my code:

With ObjCreate("winhttp.winhttprequest.5.1")
    .Open("POST", 'https://api.server.ir/get', False)
    .SetRequestHeader("Content-Type", 'application/x-www-form-urlencoded')
    .SetRequestHeader("Connection", 'Keep-Alive')
    .SetRequestHeader("User-Agent", 'okhttp/3.10.0')
    .SetTimeouts(30000,60000,30000,60000)
    Do
        .Send($req[$num][0])
        Sleep(Random(100,200))
        If @error Or StringLen(.ResponseText) < 500 Then ContinueLoop            ; The error come up here!
        Global $qId = _StringBetween(.ResponseText,'","id":',',"')
        If @error Or UBound($qId) < 2 Then ContinueLoop
        Global $act=_StringBetween(.ResponseText,'"aeues":"','","'), $rank=_StringBetween(.ResponseText,'"riae":"','","')
        If @error Or IsArray($act) = 0 Or IsArray($rank) = 0 Then ContinueLoop
        Global $cAns = _ArraySearch($aResult,$qId[1],0,0,0,0,0,1)
    Until @error = 0 And $cAns > -1
    $cAns = $aResult[$cAns][12]
EndWith

That error is not always happening, just sometimes.

Edited by HamidZaeri
Link to comment
Share on other sites

Simple solution:

        .Send($req[$num][0])
        Sleep(Random(100,200))
        If .Status <> '200' Then ContinueLoop ; --> added
        If @error Or StringLen(.ResponseText) < 500 Then ContinueLoop            ; The error come up here!

 

Advanced solution:
 

$objErr = ObjEvent("AutoIt.Error","MyErrFunc")

Func MyErrFunc()
    SetError(1)
EndFunc

...

.Send(...)
If @error Then ContinueLoop

 

Edited by Zedna
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...