Content Types

One of the first things you learned in this book is that the Web server depends on the CGI program to generate the Content-type header. This is because the Web server has no way of knowing what sort of content the CGI program is going to generate. It just so happens that so far, I’ve always printed out a Content-type header that looks like this:

Content-type: text/html 

Back in lesson 6, I explained how content types work, and how servers use them. I also discussed some of the families that content types are grouped into. Sending a different content type from your CGI scripts is simple. If you want to indicate that the content returned is plain text, specify the content type as text/plain:

 print "Content-type: text/plain\n\n"; ...

Get Sams Teach Yourself CGI in 24 Hours, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.