开发者

Perl script not working.. (Error : Premature end of script headers)

开发者 https://www.devze.com 2022-12-16 23:57 出处:网络
I am trying to print a XML file in the browser using a p开发者_JS百科erl script. While I am trying to run the script in my browser I am having the following error.

I am trying to print a XML file in the browser using a p开发者_JS百科erl script. While I am trying to run the script in my browser I am having the following error.

Server error!
The server encountered an internal error and was unable to complete your request.
Error message: 
Premature end of script headers: get_data.pl

If you think this is a server error, please contact the webmaster.

Error 500

localhost
01/15/10 14:29:28
Apache/2.2.14 (Win32) DAV/2 mod_ssl/2.2.14 OpenSSL/0.9.8l mod_autoindex_color PHP/5.3.1

Here is my script.I checked the syntax too, using a syntax checker. No problem with my perl configuration, since other simple perl scripts are working fine. I think the problem will be with the "use CGI;" Guide me..

#!/usr/local/bin/perl -w 
use strict;
use CGI;
use CGI::Carp qw(fatalsToBrowser);
my $r = new CGI();
my $id  = $r->param('id');
if(!defined($id)) 
{
 print "Content-type: text/html\n\nMissing parameter: id\n";
 exit 1;
}
if($id eq '7007')
{
 print "Content-Type: text/xml\n\n";
 open INPUT, "get_data.xml";
 while(<INPUT>) {
 print $_; }
 close INPUT; 
}

OMG!! I just ranamed the file,then tried..its working!!!! What was the real problem?


First thing to do with 500 Internal Server Error is to check the web server's error log for the actual error message. It may or may not be Perl-related - one common case is that the server is not set up to execute CGI programs from the location you asked it to.

Edit: I just tried it out here and the Perl works fine. However, if an id other than 7007 is specified, I get a 500 result because the script completes and exits without sending HTTP headers (or anything else, for that matter). You always need to send HTTP headers or else the web server will report "premature end of script headers" because it stopped receiving data before seeing the end of the header.


You want my guide to Troubleshooting Perl CGI. It takes you through the steps you should follow to find the problem.


Please check where the perl is installed on your machine. Please execute command "which perl" on the prompt to get the correct location. You might be having the perl installed on "/usr/bin/perl" instead of "/usr/local/bin/perl". Otherwise your scripts seems fine.

0

精彩评论

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

关注公众号