从AS3向PHP发送数据时,部分POST数据丢失

时间:2014-04-19 07:15:17

标签: php actionscript-3 flash

我使用Greensock DataLoader将一些数据从AS3发送到PHP。这是我的代码:

var request:URLRequest = new URLRequest(PHP_LOCATION);
var data:URLVariables = new URLVariables();
data.abc = "abc";
data.pqr = voicedata;
data.def = 1;
data.xyz = "xyz";
data.lmn = "";
request.data = data;
request.method = URLRequestMethod.POST;

var dataLoader:DataLoader = new DataLoader(request, { name:"phploader", onProgress:OnProgressHandler, onComplete:OnCompleteHandler, onError:OnErrorHandler } );
dataLoader.load();

所以我用语音字节组发送一些普通的数据,比如string和int。在PHP上,我收到的数据为:

$abc = $_POST['abc'];
$def = $_POST['def'];
$pqr = $_POST['pqr'];
$xyz = $_POST['xyz'];
$lmn = $_POST['lmn'];
SomePHPFunction($abc, $def, $pqr, $xyz, $lmn);

大多数时候,功能,即AS3和PHP之间的通信工作正常。但是,发生的情况是,有时(20次中有5次)PHP函数遇到错误。我在PHP上获得的这5次错误是:

PHP Notice:  Undefined index: abc
PHP Notice:  Undefined index: lmn

出现这种情况的任何特殊原因?我不清楚为什么要收到部分数据,但部分数据不是。

有什么建议吗?

1 个答案:

答案 0 :(得分:0)

试试这个

import flash.display.*;
import flash.events.*;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.net.URLVariables;
import flash.net.URLLoaderDataFormat;
import flash.net.URLRequestMethod;

    var urlReq:URLRequest = new URLRequest ("nameofphppage.php");

    urlReq.method = URLRequestMethod.POST; 

    var urlVars:URLVariables = new URLVariables(); 
    urlVars.abc = 'abc';
    urlVars.def = 'def';
    urlVars.pqr = 'pqr';
    urlVars.xyz = 'xyz';
    urlVars.lmn = 'lmn';

    urlReq.data = urlVars;  

    var loader:URLLoader = new URLLoader (urlReq); 

    loader.dataFormat = URLLoaderDataFormat.VARIABLES; 
    loader.load(urlReq); 

然后为你的php

<?php
$abc = $_POST['abc'];
$def = $_POST['def'];
$pqr = $_POST['pqr'];
$xyz = $_POST['xyz'];
$lmn = $_POST['lmn'];
SomePHPFunction($abc, $def, $pqr, $xyz, $lmn);
?>