TL;DR version:
How do I pull a JSON object from the body of a network.request body? $_POST(‘JSONvariableName’) doesn’t exactly work(not that i expected it too!)
Long version with more explanation:
So, this is kind of a hybrid PHP/Corona question. What I am trying to do is use the network.request to POST a table that has been encoded into a JSON object that i store in the body of the request. The problem is… I don’t know how to pull the object out of the body on the PHP side. I know how to read query strings that I explicitly name, such as “score=100&level=2” or whatever but not really a JSON object whose only reference was it’s variable name in Lua. I have a feeling it’s not a difficult thing to do but my googling/forum searching skills and my non-educated guesses have not proved fruitful.
Here is some striped down sample code. I really don’t have any PHP code to provide since I am semi-clueless on what to do anyway. Actually the Lua code is probably useless given my question but here it is anyway.
[lua]-- define header
local headers = {}
headers[“Content-Type”] = “application/json”
headers[“Accept-Language”] = “en-US”
–define body
local myBody = { level=1, gametype = 5, speed = 3, score = 100 };
local jsonBody = json.encode(myBody)
–add header/body to myParams
local myParams = {}
myParams.headers = headers
myParams.body = myBody
–send request
network.request(“http://mywebsite.com/webpage.php","POST”, myNetworkListener, myParams)[/lua]
[import]uid: 147305 topic_id: 28319 reply_id: 328319[/import]