Using ComObject and WinHttp.WinHttpRequest.5.1 Topic is solved

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
nax
Posts: 3
Joined: 30 Mar 2024, 00:03

Using ComObject and WinHttp.WinHttpRequest.5.1

30 Mar 2024, 00:45

I have a program that has a webserver built-in that is used to launch an instance of the game Roblox. I'm sure I'm doing something pretty dumb but I can't get the instance to launch with AHK V2 but if I paste the URL in a browser, it works fine. Any idea?

Code: Select all

#Requires AutoHotkey v2.0

global account := "myAccountName"
global followuser := "userToFollow"
global webserverpass := "mywebserverpass"
global webserverport := "8000"

; Using this in browser works
; http://localhost:8000/FollowUser?Account=myAccountName&Username=userToFollow&Password=mywebserverpass
; Webpage result is "Joining userToFollow's game on myAccountName"
; now if I try via script....
ramURL := "http://localhost:" webserverport "/FollowUser?"
ramParams := "Account=" account "&Username=" followuser "&Password=" webserverpass
OutputDebug(ramURL ramParams "`n")
; Output is http://localhost:8000/FollowUser?Account=myAccountName&Username=userToFollow&Password=mywebserverpass
res := url_tovar(ramURL, ramParams)
OutputDebug(res "`n")
; Output is "Empty Account"

Loop
    {
        Sleep 500
    }

url_tovar(URL, param) {
    WebRequest := ComObject("WinHttp.WinHttpRequest.5.1")
    WebRequest.Open("POST", URL)
    WebRequest.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded")
    WebRequest.Send(param)
    res := WebRequest.ResponseText
    return res
    }
teadrinker
Posts: 4335
Joined: 29 Mar 2015, 09:41
Contact:

Re: Using ComObject and WinHttp.WinHttpRequest.5.1

30 Mar 2024, 06:21

res := url_tovar(ramURL . ramParams, '')
nax
Posts: 3
Joined: 30 Mar 2024, 00:03

Re: Using ComObject and WinHttp.WinHttpRequest.5.1

30 Mar 2024, 07:24

teadrinker wrote:
30 Mar 2024, 06:21
res := url_tovar(ramURL . ramParams, '')
if I do that, I get a runtime error:

Code: Select all

Error: (0x80072EFD) 
A connection with the server could not be established

Source:	WinHttp.WinHttpRequest

Specifically: Send

	031: WebRequest.Open("POST", URL)
	032: WebRequest.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded")
▶	033: WebRequest.Send(param)
	034: res := WebRequest.ResponseText
	035: Return res
	
teadrinker
Posts: 4335
Joined: 29 Mar 2015, 09:41
Contact:

Re: Using ComObject and WinHttp.WinHttpRequest.5.1  Topic is solved

30 Mar 2024, 08:07

API wrote:FollowUser
GET
nax wrote: WebRequest.Open("POST", URL)
Must be "GET" here instead of "POST".

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: FalseShepard, jaccotjuhhh, TAC109 and 37 guests