SrFabio has asked for the wisdom of the Perl Monks concerning the following question:

Hi everyone, as you can see i'm new here and also new to CGI scripting. So, what i'm doing is reading "Begining with Perl" which i found to be excelent, but i'm stuck right now in one exemple. Here i go: i have this code:
#!/usr/bin/perl # 401response.pl use warnings; use strict; use CGI; my $cgi = new CGI; print $cgi->header('type text/html','401 Authorization Required!');
I just want to know why the browser shows nothing. Error log is clear, access log says this:
127.0.0.1 - - [15/Jul/2009:01:01:53 +0000] "GET /cgi-bin/401response.p +l HTTP/1.1" 401 -
Does anyone knows what could be the problem? Shouldnt my browser show the error i've putted on header() ? (i've tested with 2 browsers). Thank you ;)

Replies are listed 'Best First'.
Re: CGI 401 Response
by ikegami (Patriarch) on Jul 15, 2009 at 01:47 UTC

    Note that 'type text/html' should be 'text/html'.

    Your browser received a 401 as shown by the access log.

    I'm not sure exactly what you expect your browser to show. You say there's a html body, but you send nothing. My browser happily displays that empty HTML doc

      Hum..i was expecting the browser to show the error like it shows when a page is not found 404 - Not Found..i was expecting something like that. Thank you ;)
        The browser displays whatever you tell it to display. If you want to it to display such a page, you need to send it such a page.
Re: CGI 401 Response
by Anonymous Monk on Jul 15, 2009 at 06:26 UTC
    use warnings; use strict; use CGI; my $cgi = new CGI; print $cgi->header('type text/html','401 Authorization Required!'); __END__ Status: 401 Authorization Required! Content-Type: type text/html
    Never heard of "type text/html" :)
      Oh that "type text/html" was to be -type "text/html" ..i was trying the thing with named args and forgot to correct that one lol. Thank you for replying ;)