代理的 Rails 应用程序
我正在实施具有 Facebook API 支持的 Rails 校友应用程序。要求之一是将应用程序中的消息直接发布到 Facebook 墙。一切似乎都工作正常,但是有一个问题我无法解决。当我在大学工作时,我收到错误“无法建立连接,因为目标机器主动拒绝”。这是因为我支持大学代理。我已经做了一些谷歌搜索并尝试了代码中的一些更改,但仍然收到相同的消息。
我能让这项工作成功的唯一方法是非常hacky的。 如果我将 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'
我怎样才能完成这项工作?
I'm implementing Rails alumni application with Facebook API support. One of the requirements is to post a message from the application directly to facebook wall. Everything seems to work fine, however there is one issue which I can't fix. When I'm working at the University, I got an error "No connection could be made because the target machine actively refused it". This is because I'm behind University proxy. I've done some googling and tried some changes in code and still got the same message.
The only way I can make this work is very hacky.
If I change the method signature in http.rb class from
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
to
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
The stack trace I got, when using default http.rb is
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'
How can I make this work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您的校友应用程序服务器在大学防火墙内运行,请使用 Net::HTTP::Proxy 而不是 Net::HTTP
例如
而不是
参考: http://www.ensta.fr/~diam/ruby/online/ruby -doc-stdlib/libdoc/net/http/rdoc/classes/Net/HTTP.html >通过代理访问
Use Net::HTTP::Proxy instead of Net::HTTP if your alumni application server is running within the university firewall
For instance
instead of
Reference : http://www.ensta.fr/~diam/ruby/online/ruby-doc-stdlib/libdoc/net/http/rdoc/classes/Net/HTTP.html > Accessing via Proxy