I seem to not be able to find any documentation on how to handler http incoming requests for agents.
Here is what I have:
http.onrequest(function) can be used to have a function called when a http request is made to the agent.
The function has two parameters (HttpRequest, HttpResponse)
The values within each of these tables to not appear documented.
Request has a body, and you call send on the response. Other than that, it appears to be a black box.
** End goal **
I’m trying to grab the GET parameters from a request.
First of all, thank you guys for such awesome device and API. I love the imp! Processing that for Arduino I had to do in some app on the web I can do now in the agent. Also, when I needed to check some value in Arduino I had to have it connected to the computer, now I just use the server.log magic and it’s there in the IDE. Really, love it!
I do have a question: I can get the query params from a GET request but how do I do it from a POST request? I used postman to send a POST to my agent URL and I know it works because I get the right response back. But when I try to get the request params I don’t get anything. Both these for loops print nothing:
` foreach(idx,val in request.query)
print(“index=”+idx+" value="+val+"
");
foreach(val in request.query)
print(“value=”+val+"
");`
@merlin13 if you open up the javascript console your probably seeing CORS errors in red. Function be low a bit crude but POST body comes as string so needs to be split up to access your POST keys
local keys = split(request.body,"&"); local keyA = split(keys[0],"="); server.log("keyA:"+keyA[1]);
That’s what http.urldecode() is for: local keys = http.urldecode(request.body); foreach(idx,val in keys) server.log("index="+idx+" value="+val+"\ ");