在 Ruby 中使用 Net::HTTP 创建带有标头信息的 HTTP POST 请求

发布于 2024-08-21 13:30:21 字数 287 浏览 2 评论 0原文

我试图以编程方式发布到互联网上的 html 表单。我已设法在请求正文中创建一个带有参数的请求,但我不知道如何使用 Net::Http 库传入 Http 标头属性。如果这可能的话有什么想法吗?...还有其他图书馆可以为我做这件事吗?

res = Net::HTTP.post_form(URI.parse('http://test.com/add_comment'),
                          {'static'=>'1', 'entry_id'=>'23942',})

Im trying to programmatically post to an html form on the internet.I have managed to create a request with parameters in the request body but I can't figure out how to pass in Http Header attributes using the Net::Http library. Any ideas if this is possible?... Any other library that would do it for me ?

res = Net::HTTP.post_form(URI.parse('http://test.com/add_comment'),
                          {'static'=>'1', 'entry_id'=>'23942',})

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

蘑菇王子 2024-08-28 13:30:21

查看 http://snippets.dzone.com/posts/show/6727

特别是行喜欢:

req = Net::HTTP::Get.new(url.path)
req.add_field("X-Forwarded-For", "0.0.0.0")

check out http://snippets.dzone.com/posts/show/6727

especially lines like:

req = Net::HTTP::Get.new(url.path)
req.add_field("X-Forwarded-For", "0.0.0.0")
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文