开发者

Internal Server Error 500 thrown from perl script -but script works fine

I have a perl script which is called via Ajax. I开发者_运维问答t simply writes 3 values to a database. The code works fine (values get written successfully) but I get an "Internal Server Error" thrown. The Errorlog says "premature end of script headers".

There was no problem with the application - it works as required and has for a few months - but I noticed the error via Firebug when testing something else.

So I started stripping perl out of the script in an attempt to locate the problem .. and continued till I only had only had two lines left .. the shebang and exit .. I still get the 500 error. Running the script direct from a browser gives the 500 error in the browser window ... from the command prompt it's fine - ie. nothing in the apache errorlog.

There is nothing wrong with the server configuration - it has hundreds of perl scripts and has been running for years.


You should output a valid CGI header first.

The server is expecting the first output from a CGI script to be the CGI header. Typically that might be as simple as print "Content-type: text/plain\n\n"; or with CGI.pm and its derivatives, print header().


If you're writing to the database and don't need to send anything back to the client the proper response is status 204:

print "Status: 204 No Response\n\n";

This makes the server happy because it's sending a complete header set, and tells the client side that the request was successful and that there is no response body to process.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜