automationautohotkey

How do I create a POST request using AutoHotKey V2?


How do I create a POST Rest API request using AutoHotKey V2? Every existing script I can find on the internet applies only to AutoHotKey V1. Are there existing utility scripts that faciliate this process?


Solution

  • Basic example of a function that uses a COM Object for HTTP Requests.

    #Requires AutoHotkey v2.0.11+
    
    url := 'https://reddit.com/r/AutoHotkey/new/'
    MsgBox(http('Post', url))
    
    http(verb, url) {
        ; https://learn.microsoft.com/en-us/windows/win32/winhttp/winhttprequest
        web := ComObject('WinHttp.WinHttpRequest.5.1')
        web.Open(verb, url)
        web.Send()
        web.WaitForResponse()
        return web.ResponseText
    }