简体   繁体   中英

Part of POST Data missing while sending data from AS3 to PHP

I am sending some data from AS3 to PHP using the Greensock DataLoader. Here is my code:

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();

So I am sending some normal data like string and int with voice bytearray . On PHP I am receiving the data as:

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

Most of the times, the functionality ie the communication between AS3 and PHP is working fine. However, what happens is, sometimes (5 out of 20 times) the PHP function encounters an error. The error I get for these 5 times on PHP is:

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

Any particular reason why this is happening? I am clueless on why part of the data is being received, but part of it is not.

Any suggestions?

Try this

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); 

and then for your php

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM