無法瀏覽 CGI 程式 (perl) malformed header from script. Bad header=<html>

/var/log/httpd/error_log

malformed header from script. Bad header=<html>

ref: http://cs.uccs.edu/~cs301/perl/perl.htm

Basically the web server complains that the wrongHello.cgi returns a web page without proper header such as "content-type: text/html " before the body of the web page <html>HelloWorld!. The header is required as the CGI secification or CGI protocol between the CGI process running the wrongHello.cgi and that of the web server. For more detail see the CGI web page.

The above hello.pl is perl script can be run standalone. It is not a CGI perl script since it did not follow the CGI protocol. In order to make that as a CGI perl script, we need to add the following two lines after #!/usr/bin/perl

use CGI qw(:standard);
print header();

or

print "content-type: text/html ";

Try http://sanluis.uccs.edu/~cs301/cgi-bin/hello.cgi or http://sanluis.uccs.edu/~cs301/cgi-bin/hello2.cgi, src, which implement the above fixes.

看到這錯誤訊息時,在 print "<html> "; 前加上 use CGI qw(:standard); print header(); 即可解決

標籤: perl
評論: 0 | 引用: 0 | 閱讀: 2580 | 列印 | 文件 | 轉發

發表評論
暱 稱: 密 碼:
網 址: E - mail:
驗證碼: 驗證碼圖片 選 項:
頭 像:
內 容:
  • 粗體
  • 斜體
  • 底線
  • 插入圖片
  • 超連結
  • 電子郵件
  • 插入引用
  • 表情符號