views:

269

answers:

1

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'

Can anyone please help, how I can make this work. Any help would be appreciated.

+1  A: 

Use Net::HTTP::Proxy instead of Net::HTTP if your alumni application server is running within the university firewall

For instance

Net::HTTP::Proxy("proxy.uni.ac.uk",8080).start( 'www.ruby-lang.org', 80 ) do |http|
     print( http.get( '/en/LICENSE.txt' ).body ) 
end

instead of

Net::HTTP.start( 'www.ruby-lang.org',80 ) do |http| 
     print( http.get( '/en/LICENSE.txt' ).body )
end

Reference : http://www.ensta.fr/~diam/ruby/online/ruby-doc-stdlib/libdoc/net/http/rdoc/classes/Net/HTTP.html > Accessing via Proxy

potatopeelings