HTTP Status Codes: A Comprehensive Guide

Listen to this Post

HTTP status codes are essential for understanding the communication between clients and servers. They provide insights into the success, failure, or need for further action in response to a client’s request. Below is a detailed breakdown of HTTP status codes, along with practical commands and steps to help you diagnose and troubleshoot issues.

You Should Know:

1. 1xx: Informational

  • 100 Continue: The server has received the initial part of the request.
  • 101 Switching Protocols: The server is switching protocols as requested by the client.

Command to Check HTTP Headers:

curl -I http://example.com

This command retrieves the HTTP headers, which include the status code.

2. 2xx: Success

  • 200 OK: The request was successful.
  • 201 Created: A new resource has been created.
  • 204 No Content: The server processed the request but isn’t returning any content.

Command to Test a Successful Request:

curl -X GET http://example.com

This command sends a GET request to the server and displays the response.

3. 3xx: Redirection

  • 301 Moved Permanently: The resource has been permanently moved.
  • 302 Found: The resource is temporarily under a different URI.
  • 304 Not Modified: The resource has not been modified since the last request.

Command to Follow Redirects:

curl -L http://example.com

The `-L` flag tells `curl` to follow redirects.

4. 4xx: Client Errors

  • 400 Bad Request: The server cannot understand the request.
  • 404 Not Found: The requested resource is not available.
  • 429 Too Many Requests: The client has sent too many requests in a given time.

Command to Simulate a 404 Error:

curl -I http://example.com/nonexistent

This command checks the headers for a non-existent resource.

5. 5xx: Server Errors

  • 500 Internal Server Error: The server encountered an unexpected condition.
  • 503 Service Unavailable: The server is temporarily unable to handle the request.

Command to Check Server Health:

ping example.com

This command checks if the server is reachable.

What Undercode Say:

Understanding HTTP status codes is crucial for debugging and optimizing web applications. Here are some additional Linux and Windows commands to help you troubleshoot:

  • Linux:
    netstat -tuln
    

    This command lists all open ports and services on a Linux server.

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

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

  • Windows:
    Test-NetConnection -ComputerName example.com -Port 80
    

    This PowerShell command tests connectivity to a specific port.

Get-EventLog -LogName System -Newest 10

This command retrieves the latest system logs for troubleshooting.

For further reading, check out these resources:

By mastering these commands and understanding HTTP status codes, you can efficiently diagnose and resolve issues in your web applications.

References:

Reported By: Sina Riyahi – Hackers Feeds
Extra Hub: Undercode MoN
Basic Verification: Pass ✅

Join Our Cyber World:

💬 Whatsapp | 💬 TelegramFeatured Image