[英]Rails application behing proxy
我正在使用Facebook API支持實現Rails校友應用程序。 要求之一是將來自應用程序的消息直接發布到Facebook牆。 一切似乎都正常,但是有一個我無法解決的問題。 當我在大學工作時,出現錯誤“無法連接,因為目標計算機主動拒絕連接”。 這是因為我落后於大學代理。 我做了一些谷歌搜索,並嘗試了一些代碼更改,但仍然收到相同的消息。
我做這項工作的唯一方法是非常棘手的。 如果我從http.rb類更改方法簽名
def HTTP.new(address, port = nil, p_addr = nil, p_port = nil, p_user = nil, p_pass = nil) h = Proxy(p_addr, p_port, p_user, p_pass).newobj(address, port) h.instance_eval { @newimpl = ::Net::HTTP.version_1_2? } h end
至
def HTTP.new(address, port = nil, p_addr = nil, p_port = nil, p_user = nil, p_pass = nil) h = Proxy("proxy.uni.ac.uk", 8080, p_user, p_pass).newobj(address, port) h.instance_eval { @newimpl = ::Net::HTTP.version_1_2? } h end
使用默認的http.rb時,我得到的堆棧跟蹤為
c:/ruby/lib/ruby/1.8/net/http.rb:565:in `initialize' c:/ruby/lib/ruby/1.8/net/http.rb:565:in `open' c:/ruby/lib/ruby/1.8/net/http.rb:565:in `connect' c:/ruby/lib/ruby/1.8/timeout.rb:48:in `timeout' c:/ruby/lib/ruby/1.8/timeout.rb:76:in `timeout' c:/ruby/lib/ruby/1.8/net/http.rb:565:in `connect' c:/ruby/lib/ruby/1.8/net/http.rb:558:in `do_start' c:/ruby/lib/ruby/1.8/net/http.rb:547:in `start' c:/ruby/lib/ruby/1.8/net/http.rb:404:in `post_form' c:/ruby/lib/ruby/gems/1.8/gems/facebooker-1.0.54/lib/facebooker/service/net_http_service.rb:4:in `post_form' c:/ruby/lib/ruby/gems/1.8/gems/facebooker-1.0.54/lib/facebooker/service.rb:78:in `post_form' c:/ruby/lib/ruby/gems/1.8/gems/facebooker-1.0.54/lib/facebooker/service.rb:66:in `post' c:/ruby/lib/ruby/gems/1.8/gems/facebooker-1.0.54/lib/facebooker/session.rb:610:in `post_without_logging' c:/ruby/lib/ruby/gems/1.8/gems/facebooker-1.0.54/lib/facebooker/session.rb:621:in `post' c:/ruby/lib/ruby/gems/1.8/gems/facebooker-1.0.54/lib/facebooker/logging.rb:20:in `log_fb_api' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.4/lib/active_support/core_ext/benchmark.rb:10:in `realtime' c:/ruby/lib/ruby/gems/1.8/gems/facebooker-1.0.54/lib/facebooker/logging.rb:20:in `log_fb_api' c:/ruby/lib/ruby/gems/1.8/gems/facebooker-1.0.54/lib/facebooker/session.rb:620:in `post'
我該如何進行這項工作?
如果校友應用服務器在大學防火牆內運行,請使用Net :: HTTP :: Proxy代替Net :: HTTP
例如
Net::HTTP::Proxy("proxy.uni.ac.uk",8080).start( 'www.ruby-lang.org', 80 ) do |http|
print( http.get( '/en/LICENSE.txt' ).body )
end
代替
Net::HTTP.start( 'www.ruby-lang.org',80 ) do |http|
print( http.get( '/en/LICENSE.txt' ).body )
end
參考: http : //www.ensta.fr/~diam/ruby/online/ruby-doc-stdlib/libdoc/net/http/rdoc/classes/Net/HTTP.html >通過代理訪問
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.