# HTTP Methods and Status Codes: Reading the Web's Conversation

You open a web server's access log and see this line:

```text
127.0.0.1 - - [30/Nov/2026 13:53:52] "GET /admin HTTP/1.1" 403 -
```

Seven words in quotes and one number. That line already tells a small story, and it is worth learning to read.

---

## Every Web Exchange Has Two Halves

In [What Actually Happens When You Type a URL Into Your Browser?](ADD-HASHNODE-URL), the browser sent a Hypertext Transfer Protocol (HTTP) request and got a response back. Here is what is inside each half.

**A request** contains:

- A **method**, which says what the client wants to do (`GET`, `POST`, and so on)
- A **target**, such as `/admin`
- **Headers**, which carry extra details
- Sometimes a **body**, such as submitted form data

**A response** contains:

- A **status code**, a three-digit number saying how it went
- **Headers**
- Usually a **body**, such as the page itself

In the log line above, the method is `GET`, the target is `/admin`, and the status code is `403`.

---

## The Methods You Will See Most

RFC (Request for Comments) 9110, the HTTP specification, defines the methods. Two properties help you reason about them.

A method is **safe** if its meaning is essentially read-only. A method is **idempotent** if sending the same request several times has the same intended effect on the server as sending it once.

| Method | Plain meaning | Safe? | Idempotent? |
| --- | --- | --- | --- |
| `GET` | Retrieve something | Yes | Yes |
| `HEAD` | Like `GET`, but headers only | Yes | Yes |
| `OPTIONS` | Ask what is supported | Yes | Yes |
| `POST` | Submit data for processing | No | No |
| `PUT` | Replace something | No | Yes |
| `DELETE` | Remove something | No | Yes |

The table reflects what the specification says. It does not guarantee how any particular server behaves.

RFC 9110 states that the safe definition does not prevent an implementation from including behavior that is not entirely read-only. A badly designed application can change data on a `GET` request, and that is a design flaw worth catching.

---

## Status Codes: Five Families

The first digit tells you the family.

| Family | Meaning |
| --- | --- |
| 1xx | Informational |
| 2xx | Success |
| 3xx | Redirection: more action is needed |
| 4xx | Client error: the request has a problem |
| 5xx | Server error: the server failed on an apparently valid request |

A short list covers a large share of what you will see in logs:

| Code | Name | What it means |
| --- | --- | --- |
| 200 | OK | The request succeeded |
| 301 | Moved Permanently | The resource has a new permanent address |
| 400 | Bad Request | The server could not understand the request |
| 401 | Unauthorized | Valid authentication credentials are missing |
| 403 | Forbidden | The server understood the request and refuses it |
| 404 | Not Found | No current resource was found at that target |
| 405 | Method Not Allowed | The resource does not support that method |
| 500 | Internal Server Error | The server hit an unexpected condition |
| 502 | Bad Gateway | A gateway or proxy got an invalid response from upstream |
| 503 | Service Unavailable | Temporary overload or maintenance |

---

## 401 and 403 Are Not the Same Thing

This pair connects directly to [Authentication vs. Authorization: Why the Difference Matters](ADD-HASHNODE-URL).

**401** means the request lacks valid authentication credentials. The server is asking, "Who are you?" The specification says a 401 response must include a challenge in a `WWW-Authenticate` header.

**403** means the server understood the request and refuses to fulfill it. In practice, the server often knows who you are and has decided you are not allowed.

The name "Unauthorized" for 401 is historically confusing, because the code is really about authentication.

---

## Reading Status Codes in Logs

Status codes become useful when you pair them with context. They are clues, not verdicts.

| Pattern | What it may indicate | Questions to ask |
| --- | --- | --- |
| Many 401s from one source | Repeated failed logins, or a broken client with old credentials | Is the source known? Did a service password change? |
| Many 403s | Someone or something repeatedly requesting areas it cannot access | What was requested? Is it a misconfigured integration? |
| A burst of 404s | Scanning, a broken link, or a bad deployment | What paths? Are they real pages that moved? |
| A rise in 500s | An application bug or an overloaded dependency | What changed recently? Does it match a deployment? |
| 502 or 503 spikes | An upstream service is down or overloaded | Is the back end healthy? |

Use words like "may indicate." A cluster of 404s does not prove an attack, in the same way an indicator is not proof of compromise. See [Indicators of Compromise Aren't Proof of an Attack](ADD-HASHNODE-URL).

When one of these patterns does look interesting, [An Alert Fired. Now What? A Beginner's Guide to Security Triage](ADD-HASHNODE-URL) gives you the next steps.

For the bigger picture on where these lines come from, see [Logs Are Just Systems Telling You What Happened](ADD-HASHNODE-URL) and [What Are Logs, and Why Do Security Teams Care About Them?](ADD-HASHNODE-URL).

---

## Common Misconceptions

### "A 200 means everything was fine."

A 200 means the request succeeded. If someone requested data they should not have, a 200 is the problem. The exercise in [APIs: What They Are and Why Security Teams Care](ADD-HASHNODE-URL) shows exactly this.

### "A 403 means an attack was blocked."

It means the server refused the request. That could be an attacker, a user clicking the wrong link, or a misconfigured permission.

### "POST is more secure than GET."

POST keeps data out of the web address, so it is less likely to land in logs and browser history. Neither method protects data in transit. That job belongs to Transport Layer Security (TLS).

### "GET can never change anything."

The specification defines it as safe, but applications are written by people. A flawed application can change state on a `GET`.

### "A 404 means nothing happened."

The request still arrived and was logged. That is information.

---

## Practical Exercise: Generate and Read Your Own Log

This lab runs only on your own machine or lab VM. The server listens on `127.0.0.1`, so it is reachable only from that machine. Python's built-in server is for learning, not for production.

**Step 1: Save this as** `status_lab.py`

```python
from http.server import BaseHTTPRequestHandler, HTTPServer


class Handler(BaseHTTPRequestHandler):
    def reply(self, code, body="", extra=None):
        self.send_response(code)
        for key, value in (extra or {}).items():
            self.send_header(key, value)
        self.end_headers()
        if body:
            self.wfile.write(body.encode() + b"\n")

    def do_GET(self):
        if self.path == "/":
            self.reply(200, "Home page")
        elif self.path == "/old":
            self.reply(301, extra={"Location": "/"})
        elif self.path == "/private":
            self.reply(401, "Login required", {"WWW-Authenticate": 'Basic realm="lab"'})
        elif self.path == "/admin":
            self.reply(403, "You may not do that")
        elif self.path == "/crash":
            self.reply(500, "Something broke on the server")
        else:
            self.reply(404, "Nothing here")

    def do_POST(self):
        if self.path == "/form":
            self.reply(200, "Form received")
        else:
            self.reply(404, "Nothing here")

    def do_DELETE(self):
        self.reply(405, "Method not allowed", {"Allow": "GET, POST"})


HTTPServer(("127.0.0.1", 8081), Handler).serve_forever()
```

**Step 2: Start it in one terminal, sending its log to a file**

```bash
python3 status_lab.py 2> access.log
```

**Step 3: In a second terminal, send a mix of requests**

```bash
for path in / /old /private /admin /missing /crash; do
  printf "GET %-9s " "$path"
  curl -s -o /dev/null -w "%{http_code}\n" "http://127.0.0.1:8081$path"
done
curl -s -o /dev/null -w "POST /form  %{http_code}\n" -X POST http://127.0.0.1:8081/form
curl -s -o /dev/null -w "DELETE /    %{http_code}\n" -X DELETE http://127.0.0.1:8081/
```

Expected results:

```text
GET /         200
GET /old      301
GET /private  401
GET /admin    403
GET /missing  404
GET /crash    500
POST /form  200
DELETE /    405
```

**Step 4: Look at the redirect and the log**

```bash
curl -si http://127.0.0.1:8081/old | sed -n '1p;/Location/p'
cat access.log
grep -E '" (4|5)[0-9]{2} ' access.log
```

The first command shows the `301` and the `Location` header pointing to `/`. The `grep` pulls out only client and server errors.

Real web servers log similar fields, often with more detail.

**Questions to answer**

1. Which request got a 401, and which header told the client how to authenticate?
2. Why did `DELETE /` get a 405 instead of a 404?
3. If you saw 200 more times in a day, would you assume things were fine?
4. Which of the log lines would you want more context on, and what context?

Stop the server with Ctrl+C when you are done.

---

## Key Takeaway

Every web exchange has a method that says what the client wants and a status code that says how it went. Together they form a short, readable story in your logs.

Treat status codes as clues. Context decides whether they mean anything.

---

## Verified References

- IETF RFC 9110, HTTP Semantics (methods, Section 9; status codes, Section 15). <https://www.rfc-editor.org/rfc/rfc9110>
- MDN Web Docs, HTTP request methods. <https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Methods>
- Python documentation, http.server. <https://docs.python.org/3/library/http.server.html>
- curl documentation, command-line options (`-w` / `--write-out`). <https://curl.se/docs/manpage.html>
