Reputation: 201
I am developing my first AIR app (moving over from PHP/Javascript) and am at a stage where I want to send some data from the app back to a PHP script on my server. I have the following:
var url:String = "PHP URL HERE";
var request:URLRequest = new URLRequest(url);
var requestVars:URLVariables = new URLVariables();
requestVars.test = "1234";
request.data = requestVars;
request.method = URLRequestMethod.POST;
request.contentType = "application/xml;charset=utf-8";
var urlLoader:URLLoader = new URLLoader();
urlLoader.dataFormat = URLLoaderDataFormat.TEXT;
urlLoader.addEventListener(Event.COMPLETE, processSERPS, false, 0, true);
urlLoader.load(request);
I did have something else in the server side PHP script originally but for debugging I just changed it to dump the REQUEST array.
With the code above it will simply return nothing:
Array
(
)
But if I change the request method to Get:
request.method = URLRequestMethod.GET;
I receive:
Array
(
[test] => 1234
)
Which tells me that the code is correct, it just isn't sending the post parameters for some reason.
I would just alter the code to use GET variables but unfortunately the data I need to send is too large hence the need for POST.
Any help appreciated!
Upvotes: 3
Views: 5055
Reputation: 14276
If the value of the data property is a URLVariables object, the value of contentType must be application/x-www-form-urlencoded.
This is the default value, so just removing your assignment should do it.
Upvotes: 3