Lifecycle of a CGI POST request

A browser submits a form with method POST to a CGI script written in C. Put the stages of handling this single request in the order they occur, from the browser's request to the reply it receives.

  1. 1.

    The browser sends an HTTP request for the script URL with the form data in its body.

  2. 2.

    The web server sets environment variables such as REQUEST_METHOD and CONTENT_LENGTH for a new process.

  3. 3.

    The server adds the HTTP status line and forwards the response to the browser.

  4. 4.

    The program reads exactly CONTENT_LENGTH bytes from standard input and decodes the form fields.

  5. 5.

    The program writes a Content-Type header, a blank line and the response body to standard output.

  6. 6.

    The server starts the CGI program and connects the request body to its standard input.

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More CGI Programming Questions: