网页访问CGI文件时出现错误,错误如下
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator at root@localhost to inform them of the time this error occurred, and the actions you performed just before this error.
More information about this error may be available in the server error log.
主要是引文CGI文件中没有输出header头文件:
#!/usr/bin/perl
use JSON;
my $q = new CGI;
my %rec_hash = ('a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5);
my $json = encode_json \%rec_hash;
print "$json";
添加以下几行即可解决:
use CGI;
my $q = new CGI;
print $q->header();
在终端会输出html的部分头:
[root@bogon cgi-bin]# perl test.cgi
Content-Type: application/json; charset=UTF-8
{"e":5,"c":3,"a":1,"b":2,"d":4}