Ruby - Socks4 proxy with WWW::Mechanize and NET::HTTP::GET
I searched on google and read in the ruby manuals, b开发者_如何学运维ut 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')
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.
精彩评论