开发者

Why doesn't my Perl CGI program work on Windows?

开发者 https://www.devze.com 2022-12-24 23:32 出处:网络
I have written followingin index.pl which is the C:\\xampp\\htdocs\\perl folder: #!/usr/bin/perl print \"<html>\";

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 F开发者_高级运维F and chrome).

What would be the reason?

I have xampp and apache2.2 installed on this Windows XP system.


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.


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消