【问题标题】:Why doesn't my Perl CGI program work on Windows?为什么我的 Perl CGI 程序不能在 Windows 上运行?
【发布时间】:2023-03-05 20:16:01
【问题描述】:

我在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

【问题讨论】:

    标签: perl xampp


    【解决方案1】:

    另见How do I troubleshoot my Perl CGI Script?

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

    一个有效的HTTP response 由两部分组成:标题和正文。

    您应该确保使用正确的 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 年那样学习编程。

    【讨论】:

      【解决方案2】:

      可能是因为您没有将文本放在&lt;body&gt; 标记之间。您还必须将内容类型指定为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

      【讨论】:

      • 你给的编辑后的代码怎么用? Perl:可执行文件:\xampp\htdocs 和 \xampp\cgi-bin 允许的结尾:.pl
      • 上面的意思是你的html应该放在htdocs下,所有perl脚本都应该放在cgi-bin文件夹下
      【解决方案3】:

      我只是猜测。

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

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

      查看this documentation 寻求帮助。

      【讨论】:

      • @rics 感谢您的回复,当我运行此程序时,apache 已开启(已启动),88 也是正确的端口,因为我在 php 中创建的其他项目工作正常
      猜你喜欢
      • 2010-10-14
      • 2021-09-19
      • 1970-01-01
      • 1970-01-01
      • 2018-03-10
      • 2010-11-09
      • 2012-09-07
      • 1970-01-01
      • 2015-04-23
      相关资源
      最近更新 更多