start_form 的默认操作变量

发布于 2024-12-10 15:28:08 字数 530 浏览 0 评论 0原文

我目前正在编写自己的网络服务器来处理 cgi 脚本。在我当前的测试 perl 脚本中,我有一小段代码,

print start_html("CGI Test Page"),
   h1("CGI Test Page"),
   h2("Post Test:"),
   start_form(-method=>"POST",),
   "Post Value: ",textfield('postKey'),
   submit("Submit Post"),
   end_form;

如您所见,start_html 没有在表单定义中分配任何操作参数。但通过这段代码,我得到了该表单定义的以下 html 输出:

<form method="post" action="/cgitest.cgi%" enctype="multipart/form-data">

我将这个奇怪的字符附加到操作变量的末尾。所以我的问题是:由于我没有在 perl 脚本中定义操作值,它使用哪个环境变量来定义其操作?

I'm currently in the process of writing my own web server to handle cgi scripts. In my current test perl script, I have this little bit of code

print start_html("CGI Test Page"),
   h1("CGI Test Page"),
   h2("Post Test:"),
   start_form(-method=>"POST",),
   "Post Value: ",textfield('postKey'),
   submit("Submit Post"),
   end_form;

which as you can see, start_html has no action parameter assigned in the form definition. But with this code, I get the following html output for that form definition:

<form method="post" action="/cgitest.cgi%" enctype="multipart/form-data">

I'm getting that odd character appended to the end of the action variable. So my question is this: Since I don't define the action value in the perl script, which environment variable is it using to define its action?

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

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

发布评论

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

评论(1

油饼 2024-12-17 15:28:08

以下是 CGI.pm 源:

if (defined $action) {
   $action = $self->_maybe_escapeHTML($action);
}
else {
   $action = $self->_maybe_escapeHTML($self->request_uri || $self->self_url);
}

正如您所猜测的,如果您没有定义操作,它会尝试使用 $ENV{'REQUEST_URI'},但如果它为空,它会使用 脚本。定义该 URL 的子例程为 self_urlurl,因此希望那里的源代码将帮助您确定配置中额外的百分号来自何处。

Here is the relevant part from the CGI.pm source:

if (defined $action) {
   $action = $self->_maybe_escapeHTML($action);
}
else {
   $action = $self->_maybe_escapeHTML($self->request_uri || $self->self_url);
}

As you had guessed, if you don't define the action, it attempts to use $ENV{'REQUEST_URI'}, but if that's empty, it uses the URL of the script. The subroutines that define that URL are self_url and url, so hopefully the source code there will help you determine where in your configuration that extra percent sign is coming from.

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