为什么我的 Perl CGI 程序不能在 Windows 上运行?

发布于 2024-08-26 04:39:37 字数 454 浏览 9 评论 0原文

我在 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 系统上安装了 xamppapache2.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 技术交流群。

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

发布评论

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

评论(3

一曲琵琶半遮面シ 2024-09-02 04:39:37

另请参阅如何对 Perl CGI 脚本进行故障排除?

您的问题是由于您的脚本没有发送适当的标头。

有效的 HTTP 响应 由两部分组成:标头和正文。

您应该确保使用正确的 CGI 处理模块。 CGI.pm事实上的标准。然而,它有很多历史包袱,CGI::Simple 提供了一个更干净的选择。

使用这些模块之一,您的脚本将是:

#!/usr/bin/perl
use strict; use warnings;
use CGI::Simple;

my $cgi = CGI::Simple->new;

print $cgi->header, <<HTML;
<!DOCTYPE HTML>
<html>
<head><title>Test</title></head>
<body>
<h1>Perl CGI Script</h1>
<p>this is some text that should get displyed in browser</p>
</body>
</html>
HTML

请记住 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:

#!/usr/bin/perl
use strict; use warnings;
use CGI::Simple;

my $cgi = CGI::Simple->new;

print $cgi->header, <<HTML;
<!DOCTYPE HTML>
<html>
<head><title>Test</title></head>
<body>
<h1>Perl CGI Script</h1>
<p>this is some text that should get displyed in browser</p>
</body>
</html>
HTML

Keep in mind that print has no problem with multiple arguments. There is no reason to learn to program like it's 1999.

夏末的微笑 2024-09-02 04:39:37

也许是因为您没有将文本放在 标记之间。此外,您还必须将内容类型指定为 text/html

试试这个:

print "Content-type: text/html\n\n"; 
print "<html>";
print "<h2>PERL IT!</h2>";
print "<body>";
print "this is some text that should get displyed in browser";
print "</body>";
print "</html>";

另外,从 rics 给出的链接中,

Perl:
Executable: \xampp\htdocs and \xampp\cgi-bin
Allowed endings: .pl

你应该像这样访问你的脚本:
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 as text/html.

Try this:

print "Content-type: text/html\n\n"; 
print "<html>";
print "<h2>PERL IT!</h2>";
print "<body>";
print "this is some text that should get displyed in browser";
print "</body>";
print "</html>";

Also, from the link rics gave,

Perl:
Executable: \xampp\htdocs and \xampp\cgi-bin
Allowed endings: .pl

so you should be accessing your script like:
http://localhost/cgi-bin/index.pl

流年已逝 2024-09-02 04:39:37

我只是猜测。

  • 您是否启动了 apache 服务器?
  • 88 是访问您的 apache 的正确端口吗?

您也可以尝试http://localhost:88/perl/index.pl(因此将脚本名称添加到正确的地址)。

请查看此文档寻求帮助。

I am just guessing.

  • Have you started the apache server?
  • Is 88 the correct port for reaching your apache?

You may also try http://localhost:88/perl/index.pl (so adding the script name to the correct address).

Check this documentation for help.

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