HTTP headers, like email headers are distinguished from the body part of the returned data by an empty line (equivalent of 'print "\n\n"')

If you find "Content-type: text/html" or any other text string which you were expecting to be part of the page header being displayed at the top of the page before the contents of the page (i.e. in the body instead of being in the header) there is a good chance that the webserver is returning a blank line before your "Content-type: text/html" line is being output by your script.

This is often due to something like:

print qq~ Content-type: text/html ... (more headers) (body) ~;
If you're using print qq~... bear in mind that it prints everything between the double quote markers (in this case the tilde characters) unlike using
print <<EOT; Content-type: text-html ... (more headers) (body) EOT
which starts printing everthing after the print <<EOT; line. I sometimes found in the past that I'd done that when I'd converted over from a "print it as it looks in the code" print delimiter to quoted data.

You can fix this by putting the first line of the headers immediately after the ~ like this:

print qq~Content-type: text-html ... (more headers)
You can test the output of the server by using a web client that will dump the page with headers (like curl -i  http://myhost/ or lynx -mime_header http://myhost/ if you have access to either curl or lynx, or even by telnetting to the web port and typing in the GET command manually (if you know what you need to send to get the page you want - easy with HTTP/1.0 but maybe a bit more complicated with virtual hosts and HTTP/1.1 requests.)

If you have GET installed you can use GET -e http://myhost/ otherwise you could use a short perl script to return the entire contents - something like this:

#!/usr/bin/perl use strict; use warnings; use LWP::UserAgent; my $ua = LWP::UserAgent->new; my $url = shift; die "Usage: $0 URL\n" unless($url); my $response = $ua->get($url); die $response->status_line, $/ unless ($response->is_success); print $response->headers_as_string, $/, $response->content;
(If anybody would like to golf this example feel free - it could be great to have a one liner up one's sleeve for this!) ;o)

In reply to Re: CGI PERL and IIS by serf
in thread CGI PERL and IIS by crux_007

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.