I am having a strange problem, maybe something to do with Apache more than Perl. In my code when I write:

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

it prints that along with the code. But when I type:

$c = new CGI; $c->header();

it works fine and displays the HTML rendered output.

What could the problem be?

Thank you

Comments

Reduce your program to the smallest example that demonstrates the problem and then show us that. There is so much that could be going on that pulling a couple lines out isn't going to help us help you. :)

Written by brian d foy

Accepted Answer

Keep in mind, HTTP RFC specifies that

\r\n

is used for line delimiters, not

\n

so you want to be emitting

print "Content-Type: text/html\r\n\r\n";

Instead.

You should just use ->headers though to do this for you.

Also, note I used Camel-Case instead of lower-case. Although both should work, the Camel-Case is the notation used in the spec, so that is preferred and more likely to work on weird UA's.

Written by Kent Fredric
This page was build to provide you fast access to the question and the direct accepted answer.
The content is written by members of the stackoverflow.com community.
It is licensed under cc-wiki