为什么我的 Perl CGI 程序不能在 Windows 上运行?
我在 index.pl
中编写了以下内容,即 C:\xampp\htdocs\perl
文件夹:
#!/usr/bin/perl
print "<html>";
print "<h2>PERL IT!</h2>";
print "this is some text that should get displyed in browser";
print "</html>";
当我浏览到 http://localhost:88/ 时perl/
上面的 HTML 没有显示(我在 IE FF 和 chrome 中尝试过)。
原因是什么?
我在此 Windows XP 系统上安装了 xampp
和 apache2.2
。
I have written following in index.pl
which is the C:\xampp\htdocs\perl
folder:
#!/usr/bin/perl
print "<html>";
print "<h2>PERL IT!</h2>";
print "this is some text that should get displyed in browser";
print "</html>";
When I browse to http://localhost:88/perl/
the above HTML doesn't get displayed (I have tried in IE FF and chrome).
What would be the reason?
I have xampp
and apache2.2
installed on this Windows XP system.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
另请参阅如何对 Perl CGI 脚本进行故障排除?。
您的问题是由于您的脚本没有发送适当的标头。
有效的 HTTP 响应 由两部分组成:标头和正文。
您应该确保使用正确的 CGI 处理模块。 CGI.pm 是事实上的标准。然而,它有很多历史包袱,CGI::Simple 提供了一个更干净的选择。
使用这些模块之一,您的脚本将是:
请记住 print 有多个参数没有问题。没有理由像 1999 年那样学习编程。
See also How do I troubleshoot my Perl CGI Script?.
Your problem was due to the fact that your script did not send the appropriate headers.
A valid HTTP response consists of two sections: Headers and body.
You should make sure that you use a proper CGI processing module. CGI.pm is the de facto standard. However, it has a lot of historical baggage and CGI::Simple provides a cleaner alternative.
Using one of those modules, your script would have been:
Keep in mind that print has no problem with multiple arguments. There is no reason to learn to program like it's 1999.
也许是因为您没有将文本放在
标记之间。此外,您还必须将内容类型指定为
text/html
。试试这个:
另外,从 rics 给出的链接中,
你应该像这样访问你的脚本:
http://localhost/cgi-bin/index.pl
Maybe it's because you didn't put your text between
<body>
tags. Also you have to specify the content type astext/html
.Try this:
Also, from the link rics gave,
so you should be accessing your script like:
http://localhost/cgi-bin/index.pl
我只是猜测。
apache
服务器?88
是访问您的apache
的正确端口吗?您也可以尝试
http://localhost:88/perl/index.pl
(因此将脚本名称添加到正确的地址)。请查看此文档寻求帮助。
I am just guessing.
apache
server?88
the correct port for reaching yourapache
?You may also try
http://localhost:88/perl/index.pl
(so adding the script name to the correct address).Check this documentation for help.