405 Method Not Allowed
405 Method Not Allowed means the server recognizes the URL but the resource does not support the HTTP method you used, such as a POST to a GET-only endpoint. The Allow response header lists the methods that work.
The URL exists, but it does not accept this HTTP method.
For example a POST to an endpoint that only defines GET. The server must list the allowed methods in an Allow header. A frequent cause is a missing trailing slash: the framework redirects to the slashed URL, the client follows with GET, and the GET-only route behind it, or a static file server, answers 405.
Explained
The spec requires an Allow header on a 405, so read it first: Allow: GET, HEAD tells you the endpoint is read-only. A missing Allow header is a server bug, but the meaning is the same.
405 differs from 501. 501 means the server does not implement the method at all; 405 means it does, but not for this resource.
A common trap is a redirect in the middle. If you POST to /api/items and the server issues a 301 or 302 to /api/items/, the client follows with GET, and a POST-only route answers 405. Use the canonical URL, or have the server redirect with 307 or 308 so the method is kept.
How to debug it
- Read the
Allowheader on the 405 response. - Check the exact URL, including the trailing slash, and whether a redirect happened before the 405 (
curl -vshows each hop). - Confirm the route is registered for this method in the framework, for example
methods=["POST"]in Flask. - If a static file server or CDN serves the path, it may only allow GET and HEAD; route API paths to the application.
- For browser requests, check whether the 405 is on the
OPTIONSpreflight; the server must answer OPTIONS for cross-origin requests to succeed.
Gotchas
- nginx returns 405 for a POST to a static file.
- Some servers return 404 instead of 405 for unsupported methods, so do not rule out a method problem just because you got a 404.
Related explainers
- 301, 302, 303, 307 and 308 redirects comparedWhich redirect to use: permanent or temporary, and whether POST stays POST. A clear comparison of 301,...
- 404 Not FoundA 404 means the server has nothing at that URL. Why routes you just deployed return 404, when to use 410...
- 401 Unauthorized vs 403 Forbidden401 means the server does not know who you are; 403 means it knows and still says no. How to tell them...