2013-04-05 11 views
0

我想序列化的AMF體與RestClient.post發送發送。如何序列化AMF體和用Ruby RocketAMF

從查爾斯代理,我可以反序列化我的請求主體,並顯示如下:

# s is the raw binary from request body 
pp RocketAMF::Envelope.new.populate_from_stream(s).messages 

enter image description here

然而,我無法弄清楚如何序列化這樣的對象,並將其發送(與RestClient.post)在身體。

回答

2

你想改變它的使用的URL,但下面的是做正確的方式。

require 'rubygems' 
require 'RocketAMF' 
require 'rest-client' 

data = [] # whatever data you want 
env = RocketAMF::Envelope.new :amf_version => 3 
env.messages << RocketAMF::Message.new('BatchController.authenticate_iphone', '/1', data) 
res = RestClient.post "http://localhost:9292/amf", env.to_s, :content_type => 'application/x-amf' 
puts RocketAMF::Envelope.new.populate_from_stream(res).inspect 
+0

非常感謝。我試圖做env.messages = RocketAMF :: Message.new(「BatchController.authenticate_iphone」,「/ 1」,數據) – ccy 2013-04-05 06:32:32

+0

我對如何使數據陣列的另一個問題。在添加的查詢反序列化的AMF請求截圖中,我有一個屬性「Object」Type和「Command」Value。我用'command = ClassCommand.new'和'RocketAMF :: ClassMapper.define {| m | m.map:爲> '的命令',:220::在props_for_serialization'塊:錯誤的參數數目(1 0)(紅寶石=> 'ClassCommand'}',但它與'rocketamf/class_mapping.rb compalins引發ArgumentError)' – ccy 2013-04-05 21:24:58

相關問題