By using this site you agree to the use of cookies by Brugbart and our partners.

Learn more

Controlling HTTP Timeouts With AutoIt

How to change the HTTP Timeouts when using Winhttprequest.5.1 with AutoIt.

Edited: 2016-01-03 01:26

Last: Setting Request Headers Next: Using Proxies

AutoIt Logo

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.

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

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

ResolveTimeoutMaximum time allowed to use when resolving a host name, such as brugbart.com, to an ip address.
ConnectTimeoutMaximum time allowed to spend when connecting to a server, if a server does not respond within this time, the connection is dropped.
SendTimeoutTimeout for individual packets. Larger packets are normally broken up into multiple smaller packets.
ReceiveTimeoutTimeout 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.