使用PHP解码amf3对象 [英] Decode amf3 object using PHP

查看:180
本文介绍了使用PHP解码amf3对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的flash代码:

  var request = new URLRequest('http://localhost/test.php'); 
request.method = URLRequestMethod.POST;
var data = new URLVariables();
var bytes:ByteArray = new ByteArray();
bytes.objectEncoding = ObjectEncoding.AMF3;
//将一个对象写入bytearray
bytes.writeObject(
{myString:Hello World}
);
data.data = bytes;
request.data = data;

var urlLoader:URLLoader = new URLLoader();
urlLoader.dataFormat = URLLoaderDataFormat.BINARY;
urlLoader.addEventListener(Event.COMPLETE,onCompleteHandler);
urlLoader.load(request);

函数onCompleteHandler(evt:Event):void {
trace(evt.target.data);



$ b

PHP代码:


 定义( AMF_AMF3,1); 
$ data = $ _POST ['data'];
echo amf_decode($ data,AMF_AMF3);

基本上我需要从Flash发送一个AMF3对象到PHP并反序列化它。我正在使用AMFEXT扩展,但无法使其工作。任何想法?

解决方案

你有没有看过AMFPHP: http://www.amfphp.org/

AMFPHP是一个免费的PHP开源实现动作消息格式(Action Message Format,AMF)AMF允许动作脚本(AS2,AS3)本地类型和对象的二进制序列化发送到服务器端服务AMFPHP面临的挑战是实现整个AMF协议,以替代Flex Data Services AMF3)和Flash Remoting(AMF0)


My flash code:

var request=new URLRequest('http://localhost/test.php');
request.method = URLRequestMethod.POST;
var data = new URLVariables();
var bytes:ByteArray = new ByteArray();
bytes.objectEncoding = ObjectEncoding.AMF3;
//write an object into the bytearray
bytes.writeObject( 
      { myString:"Hello World"} 
);
data.data = bytes;
request.data = data;

var urlLoader:URLLoader = new URLLoader();
urlLoader.dataFormat = URLLoaderDataFormat.BINARY;
urlLoader.addEventListener(Event.COMPLETE, onCompleteHandler);
urlLoader.load(request);

function onCompleteHandler(evt:Event):void {
 trace(evt.target.data);
}

PHP code:

define("AMF_AMF3",1); 
$data = $_POST['data'];
echo amf_decode($data, AMF_AMF3);

Basically I need to send an AMF3 object from Flash to PHP and unserialize it. I'm using AMFEXT extension but couldn't get it to work. Any idea?

解决方案

Have you had a look at AMFPHP: http://www.amfphp.org/

"AMFPHP is a free open-source PHP implementation of the Action Message Format(AMF). AMF allows for binary serialization of Action Script (AS2, AS3) native types and objects to be sent to server side services. AMFPHP is challenged with implementing the entire AMF protocol to be an alternative to Flex Data Services (AMF3) and Flash Remoting (AMF0)"

这篇关于使用PHP解码amf3对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆