09
Oct
调用远程URL接口的通用方法,临时封装的,还不完善,仅供参考,相信封装完善后将是一个不错的Libary,其实RESTFul的远程也类似这样,但Rails自己封装的肯定比这个要成熟的多,抽空也Copy一个出来,记录在此
require 'net/http'
require 'net/https'
require "singleton"
require "erb"
def invoke_remote
RemoteHttp.instance
end
class RemoteHttp
include Singleton
def call(host,url,request_type,params={})
http = Net::HTTP.new(host)
response, data = http.get(host+url, nil)
puts '----------------------------------------------------'
puts response
puts '----------------------------------------------------'
puts data
puts '----------------------------------------------------'
end
end
invoke_remote.call('http://www.p1.cn','/raecoo','',{})












Leave a comment
Fields in bold are required. Email addresses are never published or distributed.
Some HTML code is allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>URLs must be fully qualified (eg: http://www.raecoo.com),and all tags must be properly closed.
Line breaks and paragraphs are automatically converted.
Please keep comments relevant. Off-topic, offensive or inappropriate comments may be edited or removed.