我发展我的第一个AIR应用程序(从PHP / Javascript的移过)和我在一个阶段,我想从应用程序发送回一些数据到PHP脚本我的服务器上。我有以下几点:
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);
我也有在服务器端的PHP脚本别的东西,但最初调试我只是改变了它转储请求阵列。
I did have something else in the server side PHP script originally but for debugging I just changed it to dump the REQUEST array.
随着code以上就简单返回nothing:
With the code above it will simply return nothing:
Array ( )
但是,如果我改变请求方法获取:
But if I change the request method to Get:
request.method = URLRequestMethod.GET;
我收到了:
Array ( [test] => 1234 )
它告诉我,code是正确的,它只是不发送参数后因某种原因。
Which tells me that the code is correct, it just isn't sending the post parameters for some reason.
我只想改变code使用GET变量,但不幸的是我需要发送的数据太大,因此需要进行自检。
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.
任何帮助AP preciated!
Any help appreciated!
推荐答案有关 URLRequest.contentType :
如果data属性的值是一个URLVariables对象,值 的contentType必须是应用程序/ x-WWW的形式urlen codeD。
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.
更多推荐
AS3 AIR的URLLoader POST
发布评论