Ruby on rails Rails 1.x客户端与RESTful服务器对话
嘿,我有一个客户机,它正在将Rails 1.2.6站点与另一个以REST方式公开服务的站点集成。目前无法升级到Rails 2.x。除了直接Net::HTTP调用之外,是否有人建议使用其他方法与REST服务通信?技术或Gem建议是受欢迎的,但我看到的大多数Gem似乎都依赖于activesupport2.x,据我所知,它与rails1.x不兼容Ruby on rails Rails 1.x客户端与RESTful服务器对话,ruby-on-rails,web-services,rest,Ruby On Rails,Web Services,Rest,嘿,我有一个客户机,它正在将Rails 1.2.6站点与另一个以REST方式公开服务的站点集成。目前无法升级到Rails 2.x。除了直接Net::HTTP调用之外,是否有人建议使用其他方法与REST服务通信?技术或Gem建议是受欢迎的,但我看到的大多数Gem似乎都依赖于activesupport2.x,据我所知,它与rails1.x不兼容 提前感谢您提供的任何意见。请尝试。它对依赖关系的了解非常少,并且使向应用程序添加JSON或XML资源的消耗变得非常容易。感谢Chris Heald的回复。我
提前感谢您提供的任何意见。请尝试。它对依赖关系的了解非常少,并且使向应用程序添加JSON或XML资源的消耗变得非常容易。感谢Chris Heald的回复。我最终确实使用了Net::HTTP,因为它比我最终想象的要简单得多。HTTParty看起来可以让这更容易,但为了未来有这个问题的人的利益,我做了以下几点
# Assume @user_name and @password were previously declared to be the
# appropriate basic auth values and that the connection is open as @connection
def put(path, body, header={})
request = Net::HTTP::Put.new(path, header.merge({'Accept' => 'application/xml,application/json', 'Content-type'=>'application/json'}))
request.basic_auth(@user_name, @password)
@connection.request(request, body).body
end
def post(path, body, header={})
request = Net::HTTP::Post.new(path, header.merge({'Accept' => 'application/xml,application/json', 'Content-type'=>'application/json'}))
request.basic_auth(@user_name, @password)
@connection.request(request, body).body
end
def get(path, header={})
request = Net::HTTP::Get.new(path)
request.basic_auth(@user_name, @password)
@connection.request(request).body
end
然后,我对这些方法的输出调用了JSON::parse(),得到了一个表示JSON的哈希值,我认为可以使用它 感谢您发布您的解决方案。我刚刚遇到了同样的问题,ans很高兴能找到这样一个有用的提纲。