tags:

views:

95

answers:

2

Hello,

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

+2  A: 

Is the "content-type: text/html" the very first thing that's output? Use wget or similar to verify the actual output; don't trust your eyes or the browser's view source.

Also note that under mod_perl, CGI calls the request's send_cgi_header method instead of just printing the headers.

Is it possible you are using CGI's header() in more than one place? That's harmless, but replacing just one header() call with explicitly printing the header would give the results you see.

ysth
yes the same code works with use cgi. so thats strange :(
Alec Smart
@Alec Smart: that comment doesn't seem to be a response to what I said ??
ysth
+1  A: 

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.

Kent Fredric