I have the following PHP file which contains the following code:
<?php echo $_POST['test']; ?>
I read the documentation for UrlLoader which seemed very straight-forward and modified the ImageLoader example app to the following:
local info = TextField.new(nil, "loading...")
info:setPosition(10, 10)
stage:addChild(info)
local function onComplete(event)
info:setText("done: " .. event.data)
end
local loader = UrlLoader.new("
http://removed.com/test.php", UrlLoader.POST, "test=testing")
loader:addEventListener(Event.COMPLETE, onComplete)
When I execute this file on the Gideros Player, I expect that event.data would return 'testing', however, this is not the case. It doesn't return anything (though the TextField does say 'done: '. When I change the code on my PHP file and Lua file to use the GET method instead of POST, and change my URL, it works without a problem.
This is obviously a very basic setup but I am wondering if there is something I am missing - do I need to add additional headers to make this POST request work?
Please advise. (On an unrelated note, I did not see a way to decode JSON in the documentation - I am currently using a third party add-in, if there is a more recommended way, let me know!)
Comments
If there is a simple way to modify the headers on POSTs in the app instead of using the hack I've implemented on my web server, that would be fantastic.
http://bugs.giderosmobile.com/issues/81
There are some Lua codes around for decoding JSON. Honestly I don't know which one is better. But one is here: http://www.chipmunkav.com/downloads/otherdownloads.htm
Likes: rdkempt
header("Content-type: text/xml");
The event.data then contained all the XML data I've requested with the UrlLoader. In case of another content type you should change the "text/xml" accordingly.