Controlling HTTP Timeouts With AutoIt

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

3142 views
d

By. Jacob

Edited: 2021-04-12 08:54

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.

Normally there is no reason to use the default timeouts for new connections. The reason for this is, that long response times rarely seem to be due to connection problems. If a long response time is encountered, it is usually because the server is offline, and then you will just waste valuable time trying to establish a connection.

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 beamtic.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", "https://beamtic.com/api/user-agent", False)

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

  $oHTTP.Send()

Tools:

You can use the following API endpoints for testing purposes:

https://beamtic.com/api/user-agent
https://beamtic.com/api/request-headers

Tell us what you think:

  1. How to declare and work with variables in AutoIt, as well as some background information.
  2. Everything you need to know about working with minimized windows.
  3. How to set the request headers when performing HTTP requests.
  4. This Tutorial will focus on post requests in AutoIt, using the Winhttprequest.5.1 object.
  5. How to use while, for, and do until loops, and how to loop through arrays and object in AutoIt.

More in: AutoIt Tutorials