Ruby - Socks4 proxy with WWW::Mechanize and NET::HTTP::GET

2.2k Views Asked by At

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')
1

There are 1 best solutions below

1
On BEST ANSWER

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.