这是一种常见的Apache CGI错误,通常是由于CGI脚本在生成头信息之前就提前退出的原因引起的。要解决这个问题,请尝试以下步骤:
以下是Python代码示例,它会导致出现“End of script output before headers”错误:
#!/usr/bin/python
# This script will cause the "End of script output before headers" error
print "Content-type: text/html"
print ""
print ""
print ""
print "Test CGI "
print ""
print ""
print "Hello World!
"
print ""
print ""
在这个示例中,脚本在输出消息头之前输出了空行。要解决这个问题,我们应该把两个print
语句合并为一个,不在它们中间输出空行。如下所示:
#!/usr/bin/python
# This script will not cause the "End of script output before headers" error
print "Content-type: text/html\n\n"
print ""
print ""
print "Test CGI "
print ""
print ""
print "Hello World!
"
print ""
print ""
这样,脚本会正确输出Content