Penn State

Web Conference 2004

Writing Perl/CGI Scripts for ITS/ASET Web services

More on HTTP

<- Back - More on Perl| Up |Speaking CGI - Next ->

How HTTP works

Here is a crash course in HTTP.

HTTP sessions involve a request sent by the browser, followed by a response from the server. Some HTTP sessions may contain multiple pairs of requests and responses. The HTTP request and response each have an associated version of HTTP, which may vary if the request was at least version 1.0.

  1. When a browser wants to visit a Web page, it makes a Transmission Control Protocol (TCP) connection to the Web server and then submits a request in HTTP. It looks like the following:

    Browser --HTTP==> Web Server
    GET /users/j/c/jcd/useful/webcon/2004/helloworld.cgi HTTP/1.0
    
    

    The first word is the method, which in this case is GET. The second part is the Uniform Resource Indicator (URI) or Uniform Resource Locator (URL), the name of the file or script desired as local to the server. The last part indicates the version of HTTP the browser is speaking. In this case, it is version 1.0. Notice there is a blank line. This indicates the end of the HTTP headers. If the browser wanted to pass additional information, such as last page visited (Referer:), cookies (Cookie:) or authentication information (Authorization:) it would do so in successive lines.

  2. When the browser has finished the request, the server replies. The version of HTTP the server uses may be different than the version the browser used if it is at least 1.0. A response may look like:

    Browser <==HTTP-- Web Server
    HTTP/1.1 200 OK
    Date: Sun, 13 Jun 2004 19:47:48 GMT
    Server: Apache/1.3.12 (Unix) mod_ssl/2.6.2 OpenSSL/0.9.5a
    Connection: close
    Content-Type: text/html
    
    <html>
    <body>
    <p>Hello world!  Here is some HTML inside a basic CGI script</p>
    </body>
    </html>
    

    The first line indicates the version of HTTP, which is 1.1 in this case, followed by the status code, followed by a human readable comment. Computers usually ignore the last part and instead rely on the number. The status code 200 means "OK" or "everything was fine with the request and here is the document you asked for." Successive lines are the rest of the HTTP headers, indicating the current date according to the server, the server software, the status of the connection (closing, or left open waiting for further requests) and a content-type (or MIME type) of the document being served. The exact headers sent may vary depending on the server software, its configuration, and the type and status of the URI requested.

    There is a blank line which indicates the end of the headers. Following this is the document in its entirety.

Versions of HTTP

<- Back - More on Perl| Up |Speaking CGI - Next ->

If you have any questions, feel free to ask me - mailto:jcd@psu.edu

Content by: Jeff D'Angelo <jcd@psu.edu> © 2004

Last update on: Thursday, 17-Jun-2004 11:46:23 EDT