Net :: HTTP可以相当麻烦的标准用例!
解决方法
如果你只需要处理REST,那么
rest-client库是太棒了.
如果您使用的API不是完全RESTful的,或者即使是 – HTTParty也值得一试.它简化了使用REST API以及非RESTful Web API.查看此代码(从上述链接复制):
require 'rubygems' require 'httparty' class Representative include HTTParty format :xml def self.find_by_zip(zip) get('http://whoismyrepresentative.com/whoismyrep.PHP',:query => {:zip => zip}) end end puts Representative.find_by_zip(46544).inspect # {"result"=>{"n"=>"1","rep"=>{"name"=>"Joe Donnelly","district"=>"2","office"=>"1218 Longworth","phone"=>"(202) 225-3915","link"=>"http://donnelly.house.gov/","state"=>"IN"}}}