This AutoIt Tutorial shows how to control the timeouts of your HTTP Requests. Changing the default timeouts can be useful to prevent rare problems, such as a page not downloading due to the connection timing out before any data is received.
The HTTP timeouts can be controlled trough the SetTimeouts method of the Winhttprequest.5.1 object.
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.
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.|
All the timeouts are to be provided as milliseconds.
Where to use SetTimeouts in the AutoIt Script
When setting the timeouts, remember that it should be done before the send method, and after creating an object. I.e.
$oHTTP = ObjCreate("winhttp.winhttprequest.5.1") $oHTTP.Open("GET", "http://brugbart.com/", False) $oHTTP.SetTimeouts(30000,60000,30000,30000) $oHTTP.Send()
Recommendations on Timeouts
Normally there will be little reason to use the default timeouts, such as the timeout for making new connections. There is little reason to use a larger connection timeout, because long response times is rarely due to connection problems – if a long response time is encountered, it is usually because the server is offline, and hence you will waste valuable time trying to establish a connection.
Keep the above in mind when deciding on how long timeouts you will be using. However, it of cause depends on what you are trying to make. If it where a bot for a larger website or search engine, then it would most likely be safe to choose a very low timeout, because they typically got good servers. When the connection hangs in this case, it is usually because it is going to fail entirely.