perl - 脚本中的标题格式错误。错误 header =<!DOCTYPE html>

标签 perl header perl-module www-mechanize

我在 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/

相关文章:

linux - 如何从文件中获取唯一事件?

mysql - MySQL 和 DBI 中的 Perl 错误

perl - 对具有无序整数列的文件进行排序

c++ - “std_lib_facilities.h”显示错误

c++ - 为什么非 const、非 int/enum 静态数据成员必须在定义之外初始化?

c++ - glActiveTexutre 和 GL_TEXTURE0 不起作用,都是未声明的标识符

Perl 使用变量来引用模块会弄乱传递参数

regex - 将多段文档拆分为段落编号的句子

perl - 全局符号需要显式包名称。错误

perl - 在使用 WWW::Mechanize 获取 <td> 标记内的 <a> 时获取 <td> 文本