malformed header from script. Bad header=<!DOCTYPE html>
Asked Answered
A

2

15

I am receiving the following server error on a perl script:

malformed header from script. Bad header=: youtube_perl.pl,

Here is my source code:

#!"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;
Agoraphobia answered 25/1, 2011 at 18:0 Comment(0)
A
29

Figured it out. Had to add the following before I attempted to print the page:

print "Content-type: text/html\n\n";

I guess perl can not print html pages without defining the header first.

Agoraphobia answered 25/1, 2011 at 18:5 Comment(5)
@user589294 - No. Perl can print them. But they won't be valid HTTP responses. So if you want your HTML page printed by Perl to be transported over HTTP you need to actually print a full HTTP response - got nothing to do with PerlNicodemus
Of course Perl can print HTML pages without a header! You can't write a CGI script without printing a header, though. Better is: print $q->header();. See perldoc CGI.Expressive
You should use \x0D\x0A rather than \n as the EOL when speaking HTTP. HTTP specifies that lines should be terminated with CR-LF whereas \n is the end of line marker for your current environment, \n just happens to be \x0D\x0A for you because you're running on Windows.Maidy
Thank you! This worked! What is strange is our old scripts were working without this, and one day stopped work. Could have been a server update. Not sure. Any ideas?Squinteyed
in bash/shell \n signs are in echo not interpreted but echo adds \n automatically, so it is needed one more echo command for the outputBroddy
A
3
print "Content-type: text/html\n\n";

Use \n\n without this it will not print anything it will give:

Malformed header from script error

In your error log file.

Alamode answered 19/9, 2017 at 9:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.