Ruby - 使用 WWW::Mechanize 和 NET::HTTP::GET 的 Socks4 代理
我在谷歌上搜索并阅读了 ruby 手册,但我找不到通过socks4代理使用WWW::Mechanize和NET::HTTP::GET的方法。
我读到,WWW::Mechanize 是 UserAgent 模块的子类,因此 ->proxy() 方法可以工作。但手册只讲了http、ftp和gopher代理。
有什么想法如何支持socks4吗?以下是代码片段:
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')
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')
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能想查看 Rubyocksify。我不认为 HTTP 客户端对 SOCKS 代理有任何支持;仅用于 HTTP 的 HTTP 代理。
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.