将xml发布到rails中的rest api

时间:2010-10-22 15:16:20

标签: ruby-on-rails xml web-services rest

我需要将一些xml信息发布到一个安静的api,任何人都可以给我一个如何做到这一点的线索吗?我正在使用rails。

1 个答案:

答案 0 :(得分:2)

在rails中,使用ActiveResource,你可以这样做:

class PersonResource < ActiveResource::Base
  self.site = "http://api.people.com:3000/"
  self.proxy = "http://user:password@proxy.people.com:8080"
end

ryan = Person.new(:first => 'Ryan', :last => 'Daigle')
# the next line posts this object serialized to xml to the configured url
ryan.save                # => true

http://api.rubyonrails.org/classes/ActiveResource/Base.html

如果您要发布的网站具有自定义API(非活动资源),则必须使用Net:HTTP