2009-12-02 42 views
0

我正在使用Facebook API支持实现Rails校友应用程序。其中一个要求是将应用程序的消息直接发布到Facebook墙上。一切似乎工作正常,但有一个问题,我不能修复。当我在大学工作时,我遇到了一个错误:“由于目标机器主动拒绝,无法建立连接”。这是因为我落后于大学代理。我做了一些Google搜索,并尝试在代码中进行一些更改,但仍收到相同的消息。Rails应用程序behing代理

我可以做这项工作的唯一方法是非常hacky。 如果我改变从

 
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 

在http.rb类中的方法签名

 
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' 

人请帮助,我如何能做到这一点。任何帮助,将不胜感激。

回答

1

使用Net :: HTTP ::代理,而不是网:: 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>通过代理访问