在 Ruby 中,如何打印 URL 参数和服务器环境变量?

发布于 2024-09-06 16:25:33 字数 77 浏览 2 评论 0原文

在 Ruby(作为 .cgi 在 Web 服务器上运行)中,如何打印 URL 参数和服务器环境变量(最好不使用任何包)? (以最原始的形式)

In Ruby (running on a web server as a .cgi), how do you print out the URL params and Server environment variables, preferable without using any package? (by the rawest form)

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

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

发布评论

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

评论(2

感性不性感 2024-09-13 16:25:33

这些通过环境变量传递给 Ruby 解释器本身;因此您可能需要使用 cgi 包来获取它们。例如:

require 'cgi'
print "Content-type: text/html\n"

print CGI.new.params; 

有关更多信息,请查看 CGI 文档 http:// www.ruby-doc.org/stdlib/libdoc/cgi/rdoc/index.html

(顺便说一句,apache 使用的 mod-ruby 有缺陷;如果你想走自己的路,你应该尝试 Mongrel 和 Rack反对使用 Rails 或 Merb。)

These are passed to the Ruby interpreter itself via env variables; so you'll probably want to use the cgi package to get at them. E.g.:

require 'cgi'
print "Content-type: text/html\n"

print CGI.new.params; 

For more, view the CGI documentation at http://www.ruby-doc.org/stdlib/libdoc/cgi/rdoc/index.html

(BTW, mod-ruby that apache uses is flawed; you should try out Mongrel and Rack if you wanna go your own way as opposed to using Rails or Merb.)

抱着落日 2024-09-13 16:25:33

谢谢你的回答。我还在cgi包代码中发现了一些内容,该变量

ENV

可以用来显示所有服务器变量。即使在 shell 或命令提示符中运行 ruby​​ 或 irb,它也包含环境变量。

thanks for the answer. I also found something in the cgi package code that the variable

ENV

can be used to show all server variables. It contains environment variables even if running ruby or irb in a shell or command prompt.

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