Ruby - 使用 WWW::Mechanize 和 NET::HTTP::GET 的 Socks4 代理

发布于 2024-08-14 03:44:50 字数 649 浏览 1 评论 0原文

我在谷歌上搜索并阅读了 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

毅然前行 2024-08-21 03:44:50

您可能想查看 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文