我在 Perl 脚本上收到以下服务器错误:
malformed header from script. Bad header=: youtube_perl.pl,
这是我的源代码:
#!"C:\XAMPP\perl\bin\perl.exe" -T
use strict;
use warnings;
use CGI;
use CGI::Carp qw/fatalsToBrowser/;
use WWW::Mechanize;
my $q = CGI->new;
my $url = 'http://www.youtube.com';
my $mechanize = WWW::Mechanize->new(autocheck => 1);
$mechanize->get($url);
my $page = $mechanize->content();
print $page;
最佳答案
想通了。在尝试打印页面之前必须添加以下内容:
print "Content-type: text/html\n\n";
我猜如果不先定义标题,perl 就无法打印 html 页面。
关于perl - 脚本中的标题格式错误。错误 header =<!DOCTYPE html>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4797124/