Perl 脚本抛出内部服务器错误 500 - 但脚本工作正常
我有一个通过 Ajax 调用的 perl 脚本。它只是将 3 个值写入数据库。该代码工作正常(值已成功写入),但我抛出“内部服务器错误”。错误日志显示“脚本标头过早结束”。
该应用程序没有任何问题 - 它按要求工作并且已经运行了几个月 - 但我在测试其他内容时通过 Firebug 注意到了错误。
所以我开始从脚本中剥离 perl 试图找到问题.. 并继续直到我只剩下两行.. shebang 并退出.. 我仍然收到 500 错误。直接从浏览器运行脚本会在浏览器窗口中出现 500 错误...从命令提示符来看,这很好 - 即。 apache 错误日志中没有任何内容。
服务器配置没有任何问题 - 它有数百个 perl 脚本并且已经运行了多年。
I have a perl script which is called via Ajax. It 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该首先输出一个有效的 CGI 标头。
服务器期望 CGI 脚本的第一个输出是 CGI 标头。通常,这可能像
print "Content-type: text/plain\n\n";
一样简单,或者使用 CGI.pm 及其衍生产品print header()
。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()
.如果您正在写入数据库并且不需要向客户端发送任何内容,则正确的响应是状态 204:
这使服务器感到高兴,因为它发送了完整的标头集,并告诉客户端请求已成功并且没有响应主体需要处理。
If you're writing to the database and don't need to send anything back to the client the proper response is status 204:
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.