401 Unauthorized
When you encounter the HTTP 401 Unauthorized status code, it means the server is asking you to provide valid login credentials before accessing the requested resource.
You can Check Your URLs HTTP Code for FREE
Introduction
In Action
Sample
Conclusion
Introduction
When you encounter the HTTP 401 Unauthorized status code, it means the server is asking you to provide valid login credentials before accessing the requested resource.
It’s like a locked door that requires the right key (username and password) to enter. If you see this error, make sure to provide the correct login information to gain access.
In Action
When you encounter the HTTP 401 Unauthorized error, it means you need to provide valid login credentials before accessing the requested resource. You might need to log in or include your credentials in the HTTP request.
Remember, this is different from the 403 Forbidden error, which indicates that the action you’re trying to perform is not allowed.
When the server sends a 401 response, it will also include the WWW-Authenticate header, specifying the authentication methods it allows.
Some common authentication schemes include Basic, Bearer, Digest, HOBA, Mutual, and AWS4-HMAC-SHA256. Make sure to follow the server’s instructions and provide the correct credentials to gain access to the resource.
Sample
In this scenario, the client tries to access a protected resource, and the server sends back a 401 Unauthorized status code, indicating that authentication is required. The server also mentions that it supports basic and mutual authorization.
To gain access, the client sends a username:password pair using basic authentication in the Authorization header. Once the server verifies the credentials, it allows the client to access the requested resource.
Initial request
GET /documents/tech-news HTTP/1.1
Host: www.example.com
Initial response
HTTP/1.1 401 Unauthorized
WWW-Authenticate: Basic; realm=”Documents”
WWW-Authenticate: Mutual
Next request, including Authorization
GET /documents/tech-news HTTP/1.1
Host: www.example.com
Authorization: Basic RXhhbXBsZTphaQ==
Final response
HTTP/1.1 200 OK
Content-Type: application/pdf
Content-Length: 25000
< PDF document included in message body>
Conclusion
In conclusion, the 401 Unauthorized status code indicates that the client’s request lacks valid authentication credentials to access a protected resource. The server requires the client to provide valid login credentials or authentication information before granting access to the requested resource.