?? ch02_04.htm
字號:
<?label 2.4. Server Responses?><html><head><title>Server Responses (CGI Programming with Perl)</title><link href="../style/style1.css" type="text/css" rel="stylesheet" /><meta name="DC.Creator" content="Scott Guelich, Gunther Birznieks and Shishir Gundavaram" /><meta scheme="MIME" content="text/xml" name="DC.Format" /><meta content="en-US" name="DC.Language" /><meta content="O'Reilly & Associates, Inc." name="DC.Publisher" /><meta scheme="ISBN" name="DC.Source" content="1565924193L" /><meta name="DC.Subject.Keyword" content="stuff" /><meta name="DC.Title" content="CGI Programming with Perl" /><meta content="Text.Monograph" name="DC.Type" /></head><body bgcolor="#ffffff"><img src="gifs/smbanner.gif" alt="Book Home" usemap="#banner-map" border="0" /><map name="banner-map"><area alt="CGI Programming with Perl" href="index.htm" coords="0,0,466,65" shape="rect" /><area alt="Search this book" href="jobjects/fsearch.htm" coords="467,0,514,18" shape="rect" /></map><div class="navbar"><table border="0" width="515"><tr><td width="172" valign="top" align="left"><a href="ch02_03.htm"><img src="../gifs/txtpreva.gif" alt="Previous" border="0" /></a></td><td width="171" valign="top" align="center"><a href="index.htm">CGI Programming with Perl</a></td><td width="172" valign="top" align="right"><a href="ch02_05.htm"><img src="../gifs/txtnexta.gif" alt="Next" border="0" /></a></td></tr></table></div><hr align="left" width="515" /><h2 class="sect1">2.4. Server Responses</h2><p><a name="INDEX-367" /><a name="INDEX-368" /><a name="INDEX-369" />Serverresponses, like client requests, always contain HTTP headers and anoptional body. Here is the server response from our earlier example:</p><blockquote><pre class="code">HTTP/1.1 200 OKDate: Sat, 18 Mar 2000 20:35:35 GMTServer: Apache/1.3.9 (Unix)Last-Modified: Wed, 20 May 1998 14:59:42 GMTETag: "74916-656-3562efde"Content-Length: 141Content-Type: text/html<HTML><HEAD><TITLE>Sample Document</TITLE></HEAD><BODY> <H1>Sample Document</H1> <P>This is a sample HTML document!</P></BODY></HTML></pre></blockquote><p>The structure of the<a name="INDEX-370" /><a name="INDEX-371" /><a name="INDEX-372" />headers for theresponse is the same as for requests. The first header line has aspecial meaning, and is referred to as the status line. The remaininglines are name-value header field lines. See <a href="ch02_04.htm#ch02-45228">Figure 2-8</a>.</p><a name="ch02-45228" /><div class="figure"><img width="256" src="figs/cgi2.0208.gif" height="45" alt="Figure 2-8" /></div><h4 class="objtitle">Figure 2-8. The structure of an HTTP response header</h4><a name="ch02-19-fm2xml" /><div class="sect2"><h3 class="sect2">2.4.1. The Status Line</h3><p>The first line of the header is the status line, which includes the<a name="INDEX-373" /><a name="INDEX-374" />protocoland version just as in HTTP requests, except that this informationcomes at the beginning instead of at the end. This string is followedby a space and the three-digit status code, as well as a text versionof the status. See <a href="ch02_04.htm#ch02-66680">Figure 2-9</a>.</p><a name="ch02-66680" /><div class="figure"><img width="120" src="figs/cgi2.0209.gif" height="45" alt="Figure 2-9" /></div><h4 class="objtitle">Figure 2-9. The status line</h4><p>Web servers can send any of dozens of <a name="INDEX-375" /> <a name="INDEX-376" />status codes. For example, the serverreturns a status of <em class="emphasis">404 Not Found</em> if a documentdoesn't exist and <em class="emphasis">301 Moved Permanently</em> ifa document is moved. Status codes are grouped into five differentclasses according to their first digit:</p><dl><dt><b>1xx</b></dt><dd><p>These status codes were introduced for HTTP 1.1 and used at a lowlevel during HTTP transactions. You won't use 100-series statuscodes in <a name="INDEX-377" />CGI scripts.</p></dd><dt><b>2xx</b></dt><dd><p>200-series status codes indicate that all is well with the<a name="INDEX-378" />request.</p></dd><dt><b>3xx</b></dt><dd><p>300-series status codes generally indicate some form of<a name="INDEX-379" />redirection. The request was valid,but the browser should find the content of its response elsewhere.</p></dd><dt><b>4xx</b></dt><dd><p>400-series status codes indicate that there was an<a name="INDEX-380" />error and the server is blaming the<a name="INDEX-381" />browser for doing somethingwrong.</p></dd><dt><b>5xx</b></dt><dd><p>500-series status codes also indicate there was an error, but in thiscase the server is admitting that it or a CGI script running on theserver is the culprit.</p></dd></dl><p>We'll discuss each of the common status codes and how to usethem in your CGI scripts in the next chapter.</p></div><a name="ch02-20-fm2xml" /><div class="sect2"><h3 class="sect2">2.4.2. Server Headers</h3><p><a name="INDEX-382" /><a name="INDEX-383" /><a name="INDEX-384" />After thestatus line, the server sends its HTTP headers. Some of these serverheaders are the same headers that browsers send with their requests.The common server headers are listed in <a href="ch02_04.htm#ch02-74991">Table 2-3</a>.</p><a name="ch02-74991" /><h4 class="objtitle">Table 2-3. Common HTTP Server Headers</h4><table border="1"><tr><th><p>Header</p></th><th><p>Description</p></th></tr><tr><td><p>Content-Base</p></td><td><p>Specifies the base URL for resolving all relative URLs within thedocument</p></td></tr><tr><td><p>Content-Length</p></td><td><p>Specifies the length (in bytes) of the body</p></td></tr><tr><td><p>Content-Type</p></td><td><p>Specifies the media type of the body</p></td></tr><tr><td><p>Date</p></td><td><p>Specifies the date and time when the response was sent</p></td></tr><tr><td><p>ETag</p></td><td><p>Specifies an entity tag for the requested resource</p></td></tr><tr><td><p>Last-Modified</p></td><td><p>Specifies the date and time when the requested resource was lastmodified</p></td></tr><tr><td><p>Location</p></td><td><p>Specifies the new location for the resource</p></td></tr><tr><td><p>Server</p></td><td><p>Specifies the name and version of the web server</p></td></tr><tr><td><p>Set-Cookie</p></td><td><p>Specifies a name-value pair that the browser should provide withfuture requests</p></td></tr><tr><td><p>WWW-Authenticate</p></td><td><p>Specifies the authorization scheme and realm</p></td></tr></table><a name="ch02-21-fm2xml" /><div class="sect3"><h3 class="sect3">2.4.2.1. Content-Base</h3>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -