3

I'm developing REST API, and It should respond on request made by ahk script. I use node.js as server and mongodb as database. I tested POST my API in postman and it is working. But when I send POST requests from my ahk script, something goes wrong.


Here is my code

URL := "http://localhost:8000/createPlayer"
HttpObj := ComObjCreate("WinHttp.WinHttpRequest.5.1")




HttpObj.Open("POST", URL, 0)
HttpObj.SetRequestHeader("Content-Type", "application/json")


json_str := ({"name": "Any Name"})


Body = json_str
HttpObj.Send(Body)

MsgBox, %Body%
Result := HttpObj.ResponseText
Status := HttpObj.Status
msgbox % "status: " status "`n`nresult: " result

I tried different variations of json_str, but that didn't helped. I would really appreciate if you help me

Lajos Arpad
  • 64,414
  • 37
  • 100
  • 175

1 Answers1

2

I can see you've made the classic newbie mistake (we all make this mistake at one point at least): Change:

Body = json_str

to

Body := json_str

which will set the Body to the contents of the variable json_str, rather what it's currently doing which is setting Body directly to the string "json_str".

Simon C
  • 419
  • 3
  • 12