in reply to CGI PERL and IIS
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:
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 usingprint qq~ Content-type: text/html ... (more headers) (body) ~;
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.print <<EOT; Content-type: text-html ... (more headers) (body) EOT
You can fix this by putting the first line of the headers immediately after the ~ like this:
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.)print qq~Content-type: text-html ... (more headers)
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:
(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)#!/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;
|
|---|