HTTP Status Code - Hsanokklis/2023-2024-Tech-journal GitHub Wiki
Lab
You are going to purposely "mess up" to trigger HTTP status messages
Review HTTP Status Codes -->
HTTP Status Codes
1XX Informational Response | 2XX Successful | 3XX Redirection | 4XX Client Error | 5XX Server Error |
---|---|---|---|---|
100 Continue |
200 OK |
301 Move permanently |
400 Bad Request |
500 Internal Server Error |
101 Switching Protocols |
201 Created |
304 Not Modified |
401 Unauthorized |
501 Not Implemented |
102 Processing |
202 Accepted |
306 Use Proxy |
403 Forbbiden |
502 Bad Gateway |
103 Early Hints |
204 No Content |
308 Permanent Redirect |
404 Not found |
503 Service Unavailable |
404 Not Found
Error
Trigger a There are a few different ways to trigger a 404 error:
-
Type in the URL incorrectly
-
Request a resources that has been deleted
-
Request a page that has been moved to another URL and the redirection was done incorrectly.
-
Entering a domain that does not exist anymore
Triggering the Error using CLI tools
I used telnet on port 80 to try and retrieve a resource from my webserver. The funny thing is this time I wasn't attempting to to get the error, but I just so happened to. Turns out that I spelt a file name incorrectly, as you can see in the explanation below so when I tried to retrieve the file with the correctly spelling the server could not find it.
If you look closely you can see the reason this issue is cause is because I spelt Detroit wrong in the aboutDetroit.html
file, so when I requested the resource the server didn't have a file that matched my request and sent back the 404 Not Found
HTTP status code.
Triggering the Error in the web browser
In this example I simply deleted one character from the URL to make it an incorrect domain and was able to get a 404 error.
In the network tab below you can see the 404 status code in the Header of the HTTP response.
Link: https://www.udacity.com/blog/2021/03/creating-an-html-404-error-web-page.html
400 Bad Request
Error
Trigger a I used used telnet on port 80 to connect to my webserver and request a resource. I triggered the 400 error by typing HTTP\1.1
instead of HTTP/1.1
in my request. This was a bad request on the users end, and the server could not process the request since it was not the correct syntax.
400 vs 404
400 errors have more to do with incorrect syntax of a request whereas 404 errors have correct syntax but the server cannot find the resource that was requested.
401 Unauthorized
request
Trigger a Use a browser and connect to 192.168.4.242
on port 8090
. You should see a login prompt.
.
Then using CLI tools, connect to 192.168.4.242
on port 8090
, you should be able to generate a 401 error.
I used netcat to connect to the webserver and was able to get the 401 error
echo -ne 'HEAD / HTTP/1.1\r\nHost: 10.0.17.23 \r\n\r\n' | nc 192.168.4.242 8090
Trigger a 403 Forbidden Error
Using CLI tools connect to 192.168.4.243
and request the file /private/file.html
. You should receive a 403 error.
I used telnet on port 80 to get the 403 forbidden error
Here is the example on a web-browser
401 Unauthorized
vs403 Forbidden
401 means that the user does not have the valid credentials to access the resource. Whereas the 403 error means that the users has valid credentials but lacks valid permissions.
Link: https://supertokens.com/blog/http-error-codes-401-vs-403