405 Method Not Allowed — how to fix
HTTP/1.1 405 Method Not Allowed
Allow: GET, HEAD
Quick fix: Check which methods the endpoint accepts (the Allow response header lists them: curl -i -X OPTIONS https://host/path). Then either send the right method or register the method on the server route (@app.route('/x', methods=['GET','POST']), app.post(...), @PostMapping). Watch for redirects turning POST into GET and for a missing or extra trailing slash.
What it means
405 means the path exists but the method is not supported for it. It differs from 404 (no such path) and 403 (allowed method, but you may not). Per the HTTP spec the server must send an Allow header listing the methods it does accept, so look at it first:
curl -i -X POST https://example.com/api/items
curl -i -X OPTIONS https://example.com/api/items
See the HTTP status codes reference for how 405 relates to 404, 403 and 501.
Cause 1: the route doesn't register that method
Most frameworks only accept the methods you declare.
Flask (default is GET only):
@app.route("/items", methods=["GET", "POST"])
def items(): ...
Express:
app.get("/items", list);
app.post("/items", create); // without this, POST /items is not handled
Express itself answers an unmatched method with 404, but routers and frameworks built on it may return 405.
Spring:
@PostMapping("/items")
public Item create(@RequestBody Item item) { ... }
Django class-based views return 405 for any method without a matching handler method (def post(self, request)), and @require_POST / @require_http_methods restrict them explicitly.
Cause 2: POST to a static file or directory
Web servers serve static files with GET/HEAD only. nginx answers 405 Not Allowed when you POST to a static .html file, which happens when a form's action points at a page rather than at your backend. Point the form at the API route, and in nginx proxy that path to the app:
location /api/ {
proxy_pass http://127.0.0.1:3000;
}
Cause 3: a redirect changed the method
If /items redirects to /items/ (or HTTP to HTTPS) with 301 or 302, most clients repeat the request as GET, and the body is lost. The final URL may then reject GET, or a GET-only route gets what should have been a POST. Check with:
curl -i -X POST http://example.com/items
If you see Location:, call the final URL directly (matching trailing slash, https://). Servers that must redirect a POST should use 307 or 308, which keep the method.
Cause 4: the form or client sends the wrong method
HTML forms only send GET or POST; <form method="PUT"> silently becomes GET. Use fetch:
await fetch("/items/42", {
method: "PUT",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(data),
});
Frameworks like Rails and Laravel simulate PUT/DELETE in forms with a hidden _method field, which must be present.
Cause 5: CORS preflight (OPTIONS) not handled
For cross-origin requests with JSON bodies or custom headers, the browser first sends OPTIONS. If the server has no handler for it, the preflight gets 405 and the browser reports a CORS error. Enable CORS middleware on the server (e.g. cors() in Express, flask-cors, @CrossOrigin in Spring), which answers OPTIONS.
Cause 6: IIS WebDAV blocking PUT/DELETE
On IIS, the WebDAV module can intercept PUT and DELETE before they reach ASP.NET and return 405. If you don't use WebDAV, remove the WebDAVModule module and WebDAV handler in web.config.
Last updated 2026-12-03.