Operating System - Linux
1827810 Members
1925 Online
109969 Solutions
New Discussion

perl script getting http:500 response

 
SOLVED
Go to solution
Henry Chua
Super Advisor

perl script getting http:500 response

Hi guys,

I have written a perl script to post http message to a server and I am getting a response of 500 - Internal Server Error. There are no problem posting to other server so I am thinking if it is a problem with their server or simply a connectivity issue. What do you think?

Best regards
Henry
2 REPLIES 2
Steven E. Protter
Exalted Contributor
Solution

Re: perl script getting http:500 response

Shalom,

This is almost always a scripting erorr, not a network connectivity problem.

Issues I've faced in the past on this:
1) perl script tries to read a file that is not there, dies.
2) permissions on a file it needs to read is not correct.
3) Data format it needs is not what it gets.
4) Debugging print statements in the program that can be run in production.
5) Output lines at top of script commented out.

Normally I find the script and at the least get it to run properly at the command line, even if there is no ouput if that doesn't work, I next comment out the output statement redirecting output to http/text and put in write/print statements to figure out what part of the code is bad.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Ralph Grothe
Honored Contributor

Re: perl script getting http:500 response

Hi Henry,

as SEP suspects, this most likely seems to be a scripting error.
Usually the 500 HTTP RC is owed to a malformed HTTP server response header.
To avoid this it is recommended practise to rather rely on well established standard CGI modules like CGI.pm than doing the HTTP formatting, parsing and encoding by some self tinkered routine (unless you know the HTT protocol intimately and have well justified needs).
This is what the average HTTP response header should look like:

$ perl -MCGI=header -le 'print header'
Content-Type: text/html; charset=ISO-8859-1


Please, note that the HTTP header requires a CR/NL separator, which can be seen when dumped:

$ perl -MCGI=header -le 'print header'|od -c
0000000 C o n t e n t - T y p e : t e
0000020 x t / h t m l ; c h a r s e t
0000040 = I S O - 8 8 5 9 - 1 \r \n \r \n \n
0000060


But if, as you say, you are using the same Perl CGI script successfully on another server where you don't receive the 500 RC,
it probably isn't a header problem.

To find out what really causes the 500 you need to inspect that webserver's error.log for possible hints in the error message.
An alternative would be (just for debugging purposes) to dump the error messages wrapped up in HTML to your browser by inserting this import in your Perl CGI script on that webserver:

use CGI::Carp qw(fatalsToBrowser);

Madness, thy name is system administration