Decode amf3 object using PHP

可紊 提交于 2020-01-15 06:06:16

问题


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?


回答1:


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




回答2:


You can try this one - http://sourceforge.net/projects/php-amf3/




回答3:


I wrote a simple AMF3 Serializer/Deserialize in PHP for my project FlashMOG: here

It would need a bit of adaptation.




回答4:


just take a look at the AMFPHP project, I used it on a chat project and it is really simple to use and efficient.



来源:https://stackoverflow.com/questions/2628369/decode-amf3-object-using-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!