I looked at as many relevant posts I could find, but I still can’t workout why my PHP side isn’t getting the data I’m sending from the Simulator (using OSX).
Goal: Use an asynchronous HTTP call to make a network POST request to PHP from the Simulator, and have it send the POST’ed data back to the Simulator. (Assumption: If it works on Simulator, it would work on iOS device.) (Edit: I’m suing daily build 840.)
-- LUA side:
local myURL = "http://www.myWeb.com/testNetwork.php"
local function myRequest(set\_email, set\_user)
local function networkListener( event )
if ( event.isError ) then
print( "Network error!")
print ( "event.isError = ", event.isError )
print ( "event.url = ", event.url )
print ( "event.name = ", event.name )
print ( "event.response = ", event.response )
print ( "event.response = ", event.status )
else
print ( "RESPONSE: " .. event.response )
end
end
local param = {}
param.body = "email=set\_email&username=set\_user"
network.request( myURL, "POST", networkListener, params)
end
myRequest(myEmail, myUsername)
-- PHP side:
<?php <br> $email = $\_POST['email'];
$username = $\_POST['username'];
$result = array();
$result["result"] = 'Received';
$result["message"] = 'The email address we received is ' . $email . ' and username received is ' . $username;
echo json\_encode($result);
?\>
-- The terminal prints the following
RESPONSE: {"result":"Received","message":"The email address we received is and username received is "}
What I’m trying to do is so simple, and it’s pitiful that it refuses to work for me. I really want to be able to do POST (and eventually PUT), but I don’t seem to be able to make this very first baby step. What am I doing wrong?
Here are some reading I’ve done, but I’m still not getting it:
http://docs.coronalabs.com/api/library/network/request.html#examples
http://developer.coronalabs.com/forum/2011/10/11/posting-data-web-server
http://developer.coronalabs.com/forum/2012/04/03/networkrequest
http://developer.coronalabs.com/code/validation-auto-renewable-app-purchases
http://developer.coronalabs.com/forum/2012/07/15/hide-php-echo-being-browser-viewable
http://developer.coronalabs.com/forum/2012/07/19/our-server-can-not-receive-post-data-https
http://developer.coronalabs.com/forum/2012/04/16/tutorial-how-make-your-app-talk-web-service-or-how-setup-web-service-your-app-talk
Any help would be so appreciated.
Naomi
[import]uid: 67217 topic_id: 29545 reply_id: 329545[/import]
