HTTP Status Codes Explained

Listen to this Post

HTTP status codes are essential for understanding how web servers respond to client requests. They are divided into five categories, each indicating a different type of response. Below, we’ll explore these categories in detail, along with practical examples and commands to help you troubleshoot and understand web interactions better.

βœ… Successful Responses (200s)

  • 200: OK β€” The request was successful, and the server returned the requested data.
  • 201: Created β€” The request was successful, and a new resource was created.
  • 204: No Content β€” The request was successful, but there is no content to return.

You Should Know:

To check the status code of a website using `curl` in Linux:

curl -I https://example.com

This command will return the HTTP headers, including the status code.

πŸ”„ Redirection Responses (300s)

  • 301: Moved Permanently β€” The requested resource has been permanently moved to a new URL.
  • 302: Moved Temporarily β€” The requested resource has been temporarily moved to a different URL.

You Should Know:

To follow redirects using `curl`:

curl -L https://example.com

The `-L` flag ensures `curl` follows the redirects and shows the final response.

❗ Client Errors (400s)

  • 400: Bad Request β€” The server cannot process the request due to a client error.
  • 401: Unauthorized β€” Authentication is required to access the resource.
  • 403: Forbidden β€” The server refuses to fulfill the request.
  • 404: Not Found β€” The requested resource does not exist.

You Should Know:

To simulate a `404` error, you can use Python’s `requests` library:

import requests
response = requests.get('https://example.com/nonexistent')
print(response.status_code) # Output: 404

⚠️ Server Errors (500s)

  • 500: Internal Server Error β€” The server encountered an unexpected condition.
  • 501: Not Implemented β€” The server does not support the functionality required to fulfill the request.
  • 502: Bad Gateway β€” The server received an invalid response from an upstream server.
  • 503: Service Unavailable β€” The server is temporarily unable to handle the request.
  • 504: Gateway Timeout β€” The server did not receive a timely response from an upstream server.

You Should Know:

To check server logs for errors on a Linux system:

tail -f /var/log/nginx/error.log

This command monitors the Nginx error log in real-time.

What Undercode Say:

Understanding HTTP status codes is crucial for web developers, cybersecurity professionals, and IT administrators. These codes help diagnose issues, optimize web performance, and ensure secure communication between clients and servers. Below are additional commands and tools to enhance your troubleshooting skills:

  • Ping a server to check connectivity:
    ping example.com
    
  • Trace the route to a server:
    traceroute example.com
    
  • Check SSL certificate validity:
    openssl s_client -connect example.com:443
    
  • Scan for open ports using nmap:
    nmap -p 80,443 example.com
    
  • Monitor network traffic with tcpdump:
    tcpdump -i eth0 port 80
    

By mastering these commands and understanding HTTP status codes, you can effectively manage web applications, troubleshoot errors, and enhance cybersecurity measures.

Expected Output:

  • HTTP status codes categorized and explained.
  • Practical commands for troubleshooting and monitoring.
  • Enhanced understanding of web server interactions.

For further reading, visit:

References:

Reported By: Chiraggoswami23 Httpstatuscodes – Hackers Feeds
Extra Hub: Undercode MoN
Basic Verification: Pass βœ…

Join Our Cyber World:

πŸ’¬ Whatsapp | πŸ’¬ TelegramFeatured Image