Assemble AMF request with Ruby RocketAMF

你离开我真会死。 提交于 2019-12-12 00:59:21

问题


I would like to make an AMF request body the same as the followings (Charles log):

As show in Charles, it has and a "Command" value Object and a "CCLocalPlayerChanges" value Object. I am confused with the Value for such object, how can I make them using RocketAMF?

I have tried using hash for such object:

data = [{
          :method => "load",
          :service => "start.game",
          :player_delta => {:stamina => 0},
          :sequence_num => self.sequence_num,
          :transaction_time => Time.now.to_i.to_s,
          :icp => 0,
        }]

env = RocketAMF::Envelope.new :amf_version => 3
env.messages << RocketAMF::Message.new('BatchController.authenticate_iphone', '/1', data)
body = env.to_s
res = RestClient.post "http://localhost/amf", env.to_s, :content_type => 'application/x-amf'

Or ClassMapping:

class ClassCommand; attr_accessor :service, :sequence_num, :transaction_time, :icp; end;
command_obj = ClassCommand.new
command_obj.service = "start.game"
command_obj.sequence_num = 0
command_obj.transaction_time = Time.now.to_i.to_s
command_obj.icp = 0
RocketAMF::ClassMapper.define {|m| m.map :as => 'Command', :ruby => 'ClassCommand'}
data = [command_obj]

env = RocketAMF::Envelope.new :amf_version => 3
env.messages << RocketAMF::Message.new('BatchController.authenticate_iphone', '/1', data)
body = env.to_s
res = RestClient.post "http://localhost/amf", env.to_s, :content_type => 'application/x-amf'

But neither of them gives me the Value (as can see below, both objects' value are empty from Charles):

I am new to AMF, so wondering does it actually matter if the object value is empty and how to make them with RocketAMF gem.


回答1:


One idea to make your life easier is to just save the 'charles' request, then File.read it in ruby to use in the post body.



来源:https://stackoverflow.com/questions/15888962/assemble-amf-request-with-ruby-rocketamf

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