AS3 AIR URLLoader POST

拥有回忆 提交于 2019-12-10 17:49:32

问题


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!


回答1:


For URLRequest.contentType:

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.



来源:https://stackoverflow.com/questions/15012786/as3-air-urlloader-post

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!