WinHttp post request
Posted: 05 Feb 2020, 07:10
I have found this script bellow to send get Winhttp request, would like to ask for help in how i could use it to send a post request, like:
/api/item/write
So in the body:
{ "species": "value", "name": "item name", "quantity": 300 }
/api/item/write
So in the body:
{ "species": "value", "name": "item name", "quantity": 300 }
Code: Select all
getWebPage("https granblue.herokuapp.com /api/item/write/collection/550") Broken Link for safety
;=========== get the content of a webpage into a variable
getWebPage(url, postdata :="")
{
Static whr := ComObjCreate("WinHttp.WinHttpRequest.5.1") ; Static will make it use the same object in memory
whr.Open((postdata?"Post":"Get"), url, true) ; Post or Get depending if postdata is submitted
whr.SetTimeouts("30000", "30000", "30000", "30000") ; timeout 30 seconds
if (StrLen(postdata)>0)
{
whr.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded")
whr.Send(postdata)
}
else
{
whr.Send()
}
whr.WaitForResponse()
Return whr.ResponseText
}