How do I print http 404 not found header?

R

Robert Sedlacek

nntp said:
print "HTTP/1.1 404 Not Found";
do I need
[...]
Should I print
[...]

You could first say what you are trying to do. :) If you want to have a
custom ErrorDocument, print out the Data you want to sent to the browser.
And if this is html, a Content-Type set to text/html should be right.

g,
Robert
 
N

nntp

print "HTTP/1.1 404 Not Found";
do I need
print "Content-type: text/html\n\n"; after it?

Should I print
print "HTTP/1.1 404 Not Found";
print "locatioin: ...";
 
G

Gunnar Hjalmarsson

Robert Sedlacek said:
nntp said:
print "HTTP/1.1 404 Not Found";
do I need
[...]
Should I print
[...]

You could first say what you are trying to do. :) If you want to
have a custom ErrorDocument, print out the Data you want to sent to
the browser. And if this is html, a Content-Type set to text/html
should be right.

I'd advise against a customised error document. Nimda seized quite a
few servers up because they were sending customised 404 pages out. A
simple 404 not found http message left to the browser default display
mechanism is sufficient.

Nothing is preventing you from doing both, is there?

print "Status: 404 Not Found\n",
"Content-type: text/html; charset=ISO-8859-1\n",
"\n";
 
N

nntp

Nothing is preventing you from doing both, is there?

print "Status: 404 Not Found\n",
"Content-type: text/html; charset=ISO-8859-1\n",
"\n";

Do you know where I can find the correct header for 404?
You did
print "Status: 404 Not Found\n",
I did
print "HTTP:/1.1 404 Not Found\n",

I need to fake the header to make the brower think it is 404. The fact is I
am using a script to give the error.
So, when seombody visits at some.cgi?okok, I return a 404 header.
 
G

Gunnar Hjalmarsson

nntp said:
Do you know where I can find the correct header for 404?
You did
print "Status: 404 Not Found\n",
I did
print "HTTP:/1.1 404 Not Found\n",

I need to fake the header to make the brower think it is 404. The
fact is I am using a script to give the error.
So, when seombody visits at some.cgi?okok, I return a 404 header.

I thought that "Status: 404" was correct. Actually, I hope it is,
because I'm using it myself for similar purposes. ;-)

Your question is off topic here, and if you want to go into details with
respect to the HTTP specification, this is definitely the wrong place.
 
A

Alan J. Flavell

I thought that "Status: 404" was correct.

Surely CGI.pm will take care of such details?

"Status: 404 reason text" is correct for a normal CGI response, but
not for an nph response.
Actually, I hope it is,
because I'm using it myself for similar purposes. ;-)

But if, for some reason, your script were to be repurposed as an
nph script, it would have to be re-cast.
Your question is off topic here,
Right.

and if you want to go into details with respect to the HTTP
specification, this is definitely the wrong place.

But we have an FAQ which points to better places, and even to
some specifications. So we're not all bad :-}
 
J

Jürgen Exner

nntp said:
print "HTTP/1.1 404 Not Found";
do I need
print "Content-type: text/html\n\n"; after it?

No, print() statements in Perl are independent of each other. The first text
will print just fine without the second print() command.
Is there actually any programming language where you would have to issue a
second print command for the first one to print?

Now, if you _want_ to print the second line for your particular application
or not, that is a totally different questions and you should ask in a NG
that actually deals with your kind of application.

jue
 
J

Jürgen Exner

Abigail said:
nntp ([email protected]) wrote on MMMMLXVI September MCMXCIII in
<URL:{} print "HTTP/1.1 404 Not Found";
{} do I need
{} print "Content-type: text/html\n\n"; after it? [...]
Do you actually have a Perl question?

He did. He wanted to know if in Perl you can use a single print() statement
or if they must come in pairs. Or something like that....

jue
 
A

Alan J. Flavell

Correct, 10 out 10, go to the top of the class :)


It does however happen to specify HTTP responses in Section 6

That's not surprising, since it's the HTTP/1.1 specification.

As the relevant Perl FAQ says, at e.g
http://www.perldoc.com/perl5.8.4/po...e-correct-form-of-response-from-a-CGI-script-

The similarity between CGI response headers (defined in the CGI
specification) and HTTP response headers (defined in the HTTP
specification, RFC2616) is intentional, but can sometimes be
confusing.
However if you want a CGI specification the nearest I can offer was
a URL posted in another thread -->
http://hoohoo.ncsa.uiuc.edu/cgi/overview.html

Actually, I prefer the one referenced in the Perl FAQ part 9:

Current best-practice RFC draft at: http://CGI-Spec.Golux.Com/

although it never does seem to have quite made it to the
originally-mooted RFC status. Maybe the IETF don't really consider
the CGI interface to be in their parish, but Ken did an excellent
piece of work in collating a best-practice specification, and it seems
to me that it's the best that we've got (the NCSA spec is rather
informal, and leaves many questions unanswered).

U2. :-}
 
G

Greg Schmidt

No, print() statements in Perl are independent of each other. The first text
will print just fine without the second print() command.
Is there actually any programming language where you would have to issue a
second print command for the first one to print?

Hmm, maybe buffering issues due to the first text not ending with a
newline?
 
A

Alan J. Flavell

Thanks for this URL. Can, and if so would, you say why none of the
URL's indicated in it are hyperlinked?

I only provided some content to go into the POD to form that part of
the FAQ. Which then gets HTML-ified by some pod2html script, on which
others more familiar with the Perl distribution process may be able to
comment?

[...]
tyvm for this link too.

With respect, one -is- supposed to familiarise oneself with the
relevant Perl FAQs before posting here (see the regular "posting
guidelines" which appear here). I'm not saying that in any personal
capacity (my little bit of FAQ is only a microscopic part of the
whole), but on behalf of all of those who generously give their time
to offer "high signal to noise ratio" (sic) quality answers here (they
know who they are...).
 
S

Sherm Pendley

Alan said:
I only provided some content to go into the POD to form that part of
the FAQ. Which then gets HTML-ified by some pod2html script, on which
others more familiar with the Perl distribution process may be able to
comment?

If you want links in the HTML, they need to be marked as links in the
POD markup, with L<scheme://invalid.com>. That is translated to an <a
....> element by pod2html.

There are other link formats that are used to refer to other POD
documents instead of URLs - details are in "perldoc perlpod".

sherm--
 
T

Tad McClellan

Fair comment about familiarising oneself with the FAQ's.

I would like a pointer being published in this NG,


Have you see the Posting Guidelines that Alan referred you to?

either monthly or
fortnightly


The guidelines are posted here twice each week.



Why make them go out on the 'net when the same data is already
on their very own disk?

perhaps also saying " Use any or all of 'man perl', 'man perlfaq', 'man
perldoc'


Those only work on some operating systems so they will ADD to
the confusion of those that don't have "man".

A general-purpose OS-agnostic pointer is better.

and 'perldoc perldoc' to view up to date information that comes with
your distribution."


The Posting Guidelines already say that.

If this was published under the same subject line each time then it would
simplify the 'finding the FAQ' problem.


Good, then the 'finding the FAQ' problem has already been solved!

:)

Absolutely no disrespect intended to people who have put so much effort in
already to disseminating information via the FAQ: postings, but my
view of this NG is that it's not just for proficient perl programmers but also
for newbies who may actually not know where to find the information they need.
Imho, one place they should be able to find out how to access that info is
here.


This is already being done, but it only works if they actually
read the Posting Guidelines.
 
G

Gunnar Hjalmarsson

Tad said:
This is already being done, but it only works if they actually
read the Posting Guidelines.

The likelihood for that would increase if the link to the web page with
the guidelines was appended to each message.

( I have suggested that before, and you turned me down, Tad. Just
wondering if you have changed your mind. ;-) )
 
A

Alan J. Flavell

Why make them go out on the 'net when the same data is already
on their very own disk?

I don't disagree with that idea. I'm always in a bit of a quandry
when citing an FAQ in postings here. At least I know that a URL will
be recognised as a web URL, and that (in the above form) it will point
to the specific version of the FAQ that I had in mind, no matter which
version of Perl the questioner may have access to on the machine that
they use.

And then there's the problem with ActiveState Perl users, who get a
convenient "Start menu" item pointing to HTML-ified documentation, but
who I've often found will respond to mention of "perldoc" with a
"huh?".
 
T

Tad McClellan

With respect the URL Alan posted me to was one about CGI in FAQ 9 which itself
contains further CGI URLs one of which Alan also referred me to.


Read what Alan said in the parenthesis, that is why I quoted it.

I must have missed it then.

Yep.


Under what subject line?


Subject: Posting Guidelines for comp.lang.perl.misc ($Revision: 1.5 $)

I can see the stats posting
with subject line "Statistics for comp.lang.perl.misc". Via google I've been
able to go through the subject headers of the previous week's posts. (14th Oct
to 21st Oct) . I haven't found anything yet that mentions Posting Guidelines
in the subject line yet or anything other text that makes me think the message
contains a posting guideline for this NG.


I find one posted October 19th at groups.google.com...

Just to make sure we are clear on this and not talking about different things,
can we differentiate between the Perl FAQ (which, imho, is a FAQ or set of FAQs
about the language) and Posting guidelines for comp.lang.perl.misc ?


Yes, they are totally separate things.

One of them is about Perl while one of them is about the Perl newsgroup.

Putting comp.lang.perl.misc into google gives some URLs which give posting
guidelines the URL of which was previously posted this week in this NG by
myself elsewhere. In fact it's a document I am sure you are well aware of.
(http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.text)


That's the one.

When I have found the ones that are posted *here* bi-weekly I'll read them.


We'll just wait for that then.

At the moment the only posting guidelines I have are the ones you wrote,
URL already quoted, and which I hope are the same.


They are.

P.S. Just in case, posting the guidelines twice after reading this post or
just after having posted the post I am replying to, just won't do. ;-)

crontab -l
...
22 2 * * 2,5 /home/tadmc/perl/guide_clpmisc/autopost_guidelines
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top