如何使用Perl设置HTTP标头?

时间:2015-12-16 07:01:09

标签: perl http cgi

我无法在Perl中设置标头。

print "Expires: Thu, 08 May 2003 08:37:25 GMT\n\n";
print "Content-Type: text/html; charset=windows-1251\n\n";
print "Vary: Accept-Encoding\n\n";

第一个只有作品。然后我有Content-Type: text/x-perl。有什么问题?

1 个答案:

答案 0 :(得分:3)

我假设您正在使用CGI将您的Web服务器连接到Perl。 CGI使用空行将标题与响应正文分开。由于

print "Expires: Thu, 08 May 2003 08:37:25 GMT\n\n";

Expires:标题后打印一个空行,其余的打印语句被认为是正文的一部分,而不是标题。你想要:

print "Expires: Thu, 08 May 2003 08:37:25 GMT\n";
print "Content-Type: text/html; charset=windows-1251\n";
print "Vary: Accept-Encoding\n\n";
相关问题