start_form 的默认操作变量
我目前正在编写自己的网络服务器来处理 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
以下是 CGI.pm 源:
正如您所猜测的,如果您没有定义操作,它会尝试使用
$ENV{'REQUEST_URI'}
,但如果它为空,它会使用 脚本。定义该 URL 的子例程为self_url
和
url
,因此希望那里的源代码将帮助您确定配置中额外的百分号来自何处。Here is the relevant part from the CGI.pm source:
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 areself_url
andurl
, so hopefully the source code there will help you determine where in your configuration that extra percent sign is coming from.