Sobes.tech
Junior — Middle

What does the HTTP status code 401 mean and in what cases is it used?

sobes.tech AI

Answer from AI

HTTP status 401 Unauthorized means that the request requires user authentication. The server has received the request, but access to the resource is denied without proper or valid credentials.

When a client receives a 401, it should provide correct authentication data (such as login and password) and resend the request.

Example of usage:

  • A web server requires authorization to access a protected page.
  • The client sends a request without a token or with an invalid token.
  • The server responds with 401, indicating that authentication is needed.

It is important not to confuse 401 with 403 Forbidden: 403 means that authentication was successful, but access is forbidden.