Using Proxies with AutoIt and WinHttpRequest.5.1

AutoIt Tutorial on how to make your programs use a proxy server to send HTTP Requests.

3901 views

Edited: 2021-04-12 08:54

AutoIt Logo

Making your AutoIt HTTP Requests go trough a proxy is very easy, all you really have to do, is add a single line of code to the examples provided in the last AutoIt Tutorials. The difficult part can be to make it work with the popular "SOCKS" proxy servers, how to do that will not be covered in this Tutorial, but you can use programs such as Privoxy to make your AutoIt programs indirectly use SOCKS proxies.

Using proxies with AutoIt can be useful in many situations, mostly to avoid IP bans or hide your own IP address however – this most likely means that you will be breaking some rules somewhere.

AutoIt With Proxies

To use a proxy server with winhttprequest in AutoIt, you need to use the SetProxy method of winhttprequest, this can be done by adding the method before the Send method has been used. The method looks like the below:

$oHttp.SetProxy(2,"10.0.0.4:80")

Replace the IP number with the proxy that you want to use, the part after the colon ":" is the port number of the proxy – this is often 80 or 8080. Adding the SetProxy method to one of the AutoIt examples from earlier would give us the following code:

$oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
$oHTTP.Open("GET", "https://beamtic.com/api/user-agent", False)
$oHttp.SetProxy(2,"10.0.0.4:80")

$oHTTP.Send()
$oReceived = $oHTTP.ResponseText
$oStatusCode = $oHTTP.Status

If $oStatusCode == 200 then
 $file = FileOpen("Received.html", 2) ; The value of 2 overwrites the file if it already exists
 FileWrite($file, $oReceived)
 FileClose($file)
EndIf

What are proxy servers?

Proxy servers are used to hide your real IP address, making it difficult to track your movements on the internet.

When it comes to automation, proxy servers are often used to get around limits and blocks associated with different online services.

SOCKS Proxies and AutoIt

AutoIt does not natively support SOCKS proxy servers, you can however script it yourself – but that can be a tedious task. It's better to use a proxy, such as Privoxy, to route HTTP traffic trough the SOCKS server.

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