On Windows, you have to use port 80 - on Linux, Android and iOS, any port will do. Probably on OS-X as well, but I have not tested that. Anyhow, here's my two standard functions for GET and POST methods in AGK:
function getFromServer(q as string)
response as string
http = CreateHTTPConnection()
SetHTTPHost(http, ip.api, ip.tls)
SetHTTPTimeout(http, 5000)
SendHTTPRequestASync(http, q)
while GetHTTPResponseReady(http) = 0
print("Connecting...")
sync()
endWhile
if GetHTTPResponseReady(http) = -1
print("Connection failed!")
httpOK = false
response = ""
else
response = GetHTTPResponse(http)
httpOK = true
endif
CloseHTTPConnection(http)
DeleteHTTPConnection(http)
endFunction response
function postToServer(q as string, p as string)
response as string
http = CreateHTTPConnection()
SetHTTPHost(http, ip.api, ip.tls)
SetHTTPTimeout(http, 5000)
SendHTTPRequestASync(http, q, p)
while GetHTTPResponseReady(http) = 0
print("Connecting...")
sync()
endWhile
if GetHTTPResponseReady(http) = -1
print("Connection failed!")
httpOK = false
response = ""
else
response = GetHTTPResponse(http)
httpOK = true
endif
CloseHTTPConnection(http)
DeleteHTTPConnection(http)
endFunction response
Mind you, there are two globals here, the ip struct which gets its values from an external file at startup, and the httpOK variable that I use in other parts of the code to trigger different events based upon success or not of the API call. Also the false and true evals are defined as 0 and 1 respectively in the start of the main.agc file, like so:
#constant false = 0
#constant true = 1
#constant nil = -1
To use the two functions above, you just fill and send a query string to them. Like so with GET for instance:
function downloadHash(in as string)
query as string
out as string
query = "getHash?catID=" + in
out = getFromServer(query)
endFunction out
...and for POST:
function uploadDeviceInfo(dev as device_t)
query as string
query = "postID"
msg as string
out as string
out = "Width=" + str(dev.width)
out = out + "&Height=" + str(dev.height)
out = out + "&Aspect=" + dev.aspect
out = out + "&ID=" + dev.id
out = out + "&OS=" + dev.os
out = out + "&Model=" + dev.model
msg = postToServer(query, out)
endFunction msg