HTTP

HTTP 401 Unauthorized vs 405 Method Not Allowed

Both HTTP 401 (Unauthorized) and 405 (Method Not Allowed) belong to the 4xx Client Error category. 401 indicates that the request requires user authentication. The response includes a WWW-Authenticate header indicating the authentication scheme. Meanwhile, 405 means that the HTTP method is not allowed for the requested resource. The response includes an Allow header listing valid methods.

Description

The request requires user authentication. The response includes a WWW-Authenticate header indicating the authentication scheme.

When You See It

When accessing a protected resource without credentials or with expired tokens.

How to Fix

Include valid authentication credentials (API key, Bearer token, Basic auth) in the Authorization header.

Description

The HTTP method is not allowed for the requested resource. The response includes an Allow header listing valid methods.

When You See It

When sending POST to a read-only endpoint, or DELETE to a non-deletable resource.

How to Fix

Check the Allow response header for supported methods. Use the correct HTTP method.

Key Differences

1.

HTTP 401: The request requires user authentication. The response includes a WWW-Authenticate header indicating the authentication scheme.

2.

HTTP 405: The HTTP method is not allowed for the requested resource. The response includes an Allow header listing valid methods.

3.

You encounter 401 when when accessing a protected resource without credentials or with expired tokens.

4.

You encounter 405 when when sending POST to a read-only endpoint, or DELETE to a non-deletable resource.

When to Use Which

For 401 (Unauthorized): Include valid authentication credentials (API key, Bearer token, Basic auth) in the Authorization header. For 405 (Method Not Allowed): Check the Allow response header for supported methods. Use the correct HTTP method.

Learn More