Jump to content

[WinHTTP 5.1 Object] request reached timeout


nhocquan
 Share

Recommended Posts

Hi everyone,

I have a script that call this function again & again normaly

Func CallAPI($amount, $target, $condition, $API_key)
    $oHTTP.Open("POST","https://HOST?api_key="&$API_key)
    $oHTTP.SetRequestHeader('content-type','application/json')
    $oHTTP.Send('{"amount":'&$amount&',"target":'&$target&',"condition":"'&$condition&'"}')
    $Response = $oHTTP.ResponseText
    Return $Response
EndFunc

but sometime (may be after 105 request, 203 request, 1000 request, ... n request) this request error and make my script stop 

$oHTTP.Send('{"amount":'&$amount&',"target":'&$target&',"condition":"'&$condition&'"}')
$oHTTP.^ ERROR


I think sever response slow that make this request reached default timeout.

I try to set time out with hope if reached timeout this request will return error or something else and my script keep run continue

$oHTTP.SetTimeouts(30000,60000,30000,30000)
Spoiler

HTTP Timeouts With AutoIt

To easily change the timeouts, we can simply change all of them at the same time, in one line of code.


$oHTTP.SetTimeouts(30000,60000,30000,30000)

The timeouts that you set with the above line of code are as follows:

ResolveTimeout Maximum time allowed to use when resolving a host name, such as brugbart.com, to an ip address.
ConnectTimeout Maximum time allowed to spend when connecting to a server, if a server does not respond within this time, the connection is dropped.
SendTimeout Timeout for individual packets. Larger packets are normally broken up into multiple smaller packets.
ReceiveTimeout Timeout for incoming packets. Again, larger packets are normally broken into multiple smaller ones.

but it when request reached timeout, my script error, exit and return the same message above.

Anyone have any idea too fix this disadvantage, or when sever response slow it will skip this request and return error code and countinue code without exit?

Thanks everyone T.T

Edited by nhocquan
Link to comment
Share on other sites

The example from the AutoIt documentation  (ObjEvent) shows how to:

44 minutes ago, nhocquan said:

return error code and countinue code without exit

 

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

×
×
  • Create New...