3

I searched on google and read in the ruby manuals, but I couldn't find a way to use WWW::Mechanize and NET::HTTP::GET over a socks4 proxy.

I read, that WWW::Mechanize is a subclass of the UserAgent module, and that therefore the ->proxy() method would work. But the manual only talks about http, ftp and gopher proxy.

Any ideas how to support socks4? Here are the code snippets:

def get_request(url_in)
    url = URI.parse(url_in)
    req = Net::HTTP::Get.new(url.path, {"User-Agent" => $UserAgent})

    res = Net::HTTP.start(url.host, url.port) { |http|
        http.request(req)
    }


    return res.body
end
 agent       = WWW::Mechanize.new
    agent.user_agent_alias('Windows Mozilla')
    page        = agent.get("urlhere")
    post_form   = page.form('post')
blahdiblah
  • 33,069
  • 21
  • 98
  • 152
maxedmelon
  • 251
  • 4
  • 17

1 Answers1

3

You probably want to look at Ruby socksify. I don't think that the HTTP client has any support for SOCKS proxies; only HTTP proxies for HTTP.

hobbs
  • 223,387
  • 19
  • 210
  • 288
  • Homepage is dead, archive here: https://web.archive.org/web/20170127085053/http://socksify.rubyforge.org/ – GDP2 Jul 14 '20 at 21:28