---
title: "HTTP working, methods, virtual hosting"
subject: "Internet and Intranet"
chapter: 4
key: "semester_8/internet_and_intranet:http-works-methods-virtual-hosting"
source: https://www.bctengineer.com/q/semester_8/internet_and_intranet/http-works-methods-virtual-hosting
site: BCT Engineering
---

# HTTP working, methods, virtual hosting

Internet and Intranet · Chapter 4: HTTP and the Web Services

- Asked in: 2073 Magh, 3+3+4 marks
- Video: [HTTP Transaction explain with real time example | Working of HTTP](https://www.youtube.com/watch?v=Nj8pGsBvcmo) — Chirag Bhalodia
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_8/internet_and_intranet/http-works-methods-virtual-hosting
- Whole chapter: https://www.bctengineer.com/md/semester_8/internet_and_intranet/chapter-4

## Question

How HTTP works? Explain different methods of HTTP. Write the concept of virtual hosting.

## Short answer

HTTP is a request-response protocol over TCP; browser requests resources, server returns status and content. Methods include GET, POST, HEAD. Virtual hosting runs multiple sites on one server via IP-based, port-based, or name-based selection.

## Answer

#### How HTTP works

**HyperText Transfer Protocol (HTTP)** is the application layer protocol of the Web. It uses a client/server request-response model over TCP (port 80; HTTPS 443). It is **stateless**: the server keeps no memory of earlier requests.

1. The user types a URL, e.g. `http://www.example.com/index.html`.
2. The browser asks DNS for the IP address of `www.example.com`.
3. The browser opens a TCP connection to port 80 of the server.
4. It sends an HTTP request message (request line, headers, blank line, optional body).
5. The server finds the object and sends a response (status line such as `200 OK`, headers, body).
6. The browser parses the HTML; for each embedded object (image, CSS) it sends further requests.
7. The connection is closed (HTTP/1.0) or kept alive (HTTP/1.1 persistent).

```text
 Browser                        Web server
   |--- TCP connect ----------->|
   |--- GET /index.html ------->|
   |<-- 200 OK + HTML ----------|
   |--- GET /logo.png --------->|
   |<-- 200 OK + image ---------|
```

#### HTTP methods

- **GET**: retrieve a resource.
- **POST**: send form data in the body for processing.
- **HEAD**: headers only, no body.
- **PUT**: upload or replace a resource.
- **DELETE**: remove a resource.
- **OPTIONS** and **TRACE**: query the server's capabilities, and echo the request back for testing.

#### Virtual hosting

Virtual hosting runs several web sites on one server machine, saving hardware and IP addresses. Types: **IP-based** (a different IP per site), **port-based** (a different port per site) and **name-based** (same IP; the `Host:` header selects the site). Example: `www.a.com` and `www.b.com` both at 192.168.1.10, each with its own `<VirtualHost>` and `DocumentRoot` in Apache.

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. Which describes HTTP?
   A. Stateful, runs over UDP
   B. Stateless request-response protocol over TCP (port 80)
   C. Peer-to-peer, runs over UDP port 53
   D. Stateful, uses port 25
   Answer: B. HTTP is a stateless client/server request-response protocol over TCP; the server remembers nothing of earlier requests. (Key point: HTTP model)

2. What happens first when a user types a URL?
   A. Server sends 200 OK
   B. Browser asks DNS for the server IP, then opens a TCP connection and sends the request
   C. Browser parses HTML
   D. Browser sends POST
   Answer: B. The browser resolves the host name, connects to port 80, sends the request, then parses the response and requests embedded objects. (Key point: Order of HTTP operation)

3. After receiving the base HTML page, how does the browser get images and CSS?
   A. They arrive inside the same response automatically
   B. It sends further requests for each embedded object
   C. It uses SMTP
   D. It asks DNS for each pixel
   Answer: B. The browser parses the HTML and sends a further request for each embedded object. (Key point: Embedded objects)

4. How does the server choose a site in name-based virtual hosting?
   A. By the destination port
   B. By the client's IP
   C. By the Host: header of the request
   D. By the HTTP method
   Answer: C. Several names share one IP and port; the Host header selects the matching VirtualHost. (Key point: Name-based virtual hosting)

## Related in Internet and Intranet

- [HTTP request methods; web server and virtual hosting](https://www.bctengineer.com/question.md?key=semester_8%2Finternet_and_intranet%3Ahttp-methods-config-virtual-hosting) — Internet and Intranet, chapter 4
- [Virtual hosting and HTTP connections](https://www.bctengineer.com/question.md?key=semester_8%2Finternet_and_intranet%3Avirtual-hosting-http-connections) — Internet and Intranet, chapter 4
- [Virtual hosting types; name-based steps](https://www.bctengineer.com/question.md?key=semester_8%2Finternet_and_intranet%3Avirtual-hosting-types-named-steps) — Internet and Intranet, chapter 4, asked 2×
- [Short note: Web virtual hosting](https://www.bctengineer.com/question.md?key=semester_8%2Finternet_and_intranet%3Anote-virtual-hosting) — Internet and Intranet, chapter 4, asked 2×
