Chinaunix
标题:
linux下编写HTML时钟小程序,页面无法显示
[打印本页]
作者:
bianjiang007
时间:
2009-07-19 00:08
标题:
linux下编写HTML时钟小程序,页面无法显示
代码如下:
#!/usr/bin/perl -w
use strict;
use CGI qw(:push -nph);
$|=1;
print multipart_init;
while(1)
{
print multipart_start;
print "The time is <H1>", scalar(localtime),"</H1>\n";
print multipart_end;
sleep 2;
}
即实现两秒钟刷新页面一次,并显示时间。但是使用firefox无法显示,也不出现错误提示,状态一直在“载入中”,查了下apache错误日志:
[Sun Jul 19 00:04:52 2009] [error] [client ::1] malformed header from script. Bad header=HTTP/1.1 200 OK: time.cgi
麻烦大家看看是什么问题?
作者:
bianjiang007
时间:
2009-07-19 08:46
标题:
回复 #1 bianjiang007 的帖子
我的使用的版本是v5.10.0 built for i486-linux-gnu-thread-multi
刚学习perl,很多问题不明白,希望得到大家的指教,谢谢了~
作者:
xiaoshengcaicai
时间:
2009-07-20 10:47
Bad header=、、
一个HTTP响应,必须先打印必要的头部,然后输出2个换行后才能打印正文
你必须先print "Content-Type: text/html\n\n";
作者:
bianjiang007
时间:
2009-07-20 13:07
标题:
回复 #3 xiaoshengcaicai 的帖子
print multipart_init;
这句貌似就是在告诉浏览器,随后是多部分的Web页,而不是通常的header吧?
通常的只要这样就可以了啊:print header;还是不太明白,难道和我的apache有关系么?
我的是Server version: Apache/2.2.11 (Ubuntu)
作者:
ykredrum
时间:
2009-07-20 20:34
一定要把head加上,网页才能正常显示
print header(-charset=>'gb2312');
print start_html;
放网页的html代码(不包括<html></html>)
print end_html;
作者:
bianjiang007
时间:
2009-07-21 11:46
标题:
回复 #5 ykredrum 的帖子
可是我加上之后还是不行啊~~
错误如下:
Undefined subroutine &main::header called at /usr/lib/cgi-bin/time.cgi line 8.
[Tue Jul 21 11:45:46 2009] [error] [client ::1] Premature end of script headers: time.cgi
欢迎光临 Chinaunix (http://bbs.chinaunix.net/)
Powered by Discuz! X3.2