繁体   English   中英

从AS3发送JSON到PHP

[英]Sending JSON from AS3 to PHP

我真的无法弄清楚出了什么问题。

我从AS3发送JSON到PHP:

var sendToPHPJson:String = com.adobe.serialization.json.JSON.encode(sqlResult);

myRequest = new URLRequest("http://xxx.pl/FlashFiles/Winebook/uploadToServer.php");
myLoader = new URLLoader;
myVariables = new URLVariables;
myVariables.firstProperty = sendToPHPJson;
myLoader.addEventListener(flash.events.Event.COMPLETE,onUploadingComplete);
myLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
myRequest.method = URLRequestMethod.POST;
myRequest.data = myVariables;
myLoader.load(myRequest);

我的PHP正在接收:

<?php
include "XXX.php";
$json=$_POST['firstProperty'];
$data = json_decode($json);
$answe=$data[0]->wineName;
echo "answer='".$answe."'";
?>

我收到了回答=''。 但是当我将sendToPHPJson硬编码到PHP中时,答案具有很好的价值。

有什么不对? 有什么改变?

*编辑:我做了一些搜索和重建代码:

AS3:

var url:String = "http://adres/uploadToServer.php";
var request:URLRequest = new URLRequest(url);
request.method = URLRequestMethod.POST;

var requestVars:URLVariables = new URLVariables();
requestVars.myObject = sendToPHPJson;
request.data = requestVars;

var loader:URLLoader = new URLLoader();
loader.addEventListener(flash.events.Event.COMPLETE,onUploadingComplete);
loader.load(request);

PHP:

<?php
include "XXX.php";
ob_start();
var_dump($_POST['myObject']);
print_r($_POST);
$content = ob_get_contents();
ob_end_clean();
$wynik = json_decode($content);
echo $wynik;
?>

我仍然没有得到任何数据:

private function onUploadingComplete(e:flash.events.Event):void
{
    trace("upload complete");
    trace(e.target.data);
    txtField.text = String(e.target.data);
    this.touchable = true;
}

它应该是

myRequest.data = myVariables;

此外,AS3内置了JSON顶级类,无需使用第三方库。 下次检查var_dump($ _ POST)或浏览器网络信息,您的数据是如何发送的。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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