使用 CGI 时如何在 perl 中获取 HTTP 标头
问题描述:
我正在使用 Perl/CGI/Apache 并且想要获取 X-Forwarded-For HTTP 标头.我该怎么做?
I'm using Perl/CGI/Apache and want to fetch the X-Forwarded-For HTTP header. How do I do that?
答
除了少数特殊处理的headers,CGI将Header-Name:
的值保存在环境变量中HTTP_HEADER_NAME
.因此,X-Forwarded-For
(如果存在于请求中)应该在 $ENV{HTTP_X_FORWARDED_FOR}
中找到.
Except for a few headers that are handled specially, CGI stores the value of Header-Name:
in the environment variable HTTP_HEADER_NAME
. So, X-Forwarded-For
(if present in the request) should be found in $ENV{HTTP_X_FORWARDED_FOR}
.