An HTTP 405 error means the server recognizes the request method but does not support it for the target resource. Fix it by identifying the rejected URL and method, comparing them with the endpoint's contract, and correcting the client, route handler, or deployment rule responsible. Refreshing the page rarely explains why a form's POST request is being rejected.
This guide is for developers and students debugging websites they control. A portfolio can load successfully while its contact form posts to a static file. A frontend can work locally while its deployed API route accepts a different method. Capture one failing request before changing code.
Diagnose an HTTP 405 error from the rejected request
Open the browser Network panel, preserve the log, and reproduce the action once with test data. Record the request URL, method, status, response headers, response body, and any redirect immediately before it. Include the deployment version and a timestamp when asking another developer to investigate.
A 405 response must include an Allow header listing the resource's supported methods. For example, Allow: GET, HEAD on a rejected POST suggests the resource currently advertises read methods. A missing header is a server-response defect; it does not tell you which method should replace POST. MDN 405 reference
Use the request's purpose to interpret the evidence:
- GET for the page returns 405: inspect the document route and deployment mapping. The visitor cannot reach the intended page normally.
- POST from a form returns 405: compare the form action with the deployed backend endpoint. A successful GET of the homepage proves little about submission.
- OPTIONS returns 405: check whether this is a cross-origin preflight. The browser may never send the intended POST.
- A command-line HEAD request returns 405: test the actual GET separately. A HEAD-only probe does not establish how the document responds to GET.
Do not treat every rejection as something to remove. An intentionally read-only resource should continue rejecting unsupported writes. The goal is to make the intended method work and keep the endpoint's boundary accurate.
Find which route or deployment layer rejected the method
Trace the exact path through the reverse proxy, edge rules, application router, and handler. Compare the deployed route table with local development. A route file present in source is insufficient if the production deployment only published static assets.
Common repairs follow directly from the evidence:
- The form posts to
/contact.html: implement and deploy a form endpoint, then point the action at it. A static HTML host does not become a form processor because the markup uses POST. - The handler exports GET but the client sends POST: implement the intended method in the framework's route convention, or correct the client if this is actually a read operation.
- A proxy method rule rejects the request before the app: change the specific route rule after confirming the endpoint contract. Compare edge and application logs to identify the rejecting layer.
- A rewrite sends
/api/previewto the frontend shell: exclude the API route from the fallback and verify its response type. A 200 HTML shell is also a broken API response. - The endpoint path changed between releases: update the caller and deployed route together. Check case, base paths, and trailing-slash rules.
Use request IDs and matching logs to attribute the response. The response's branding can suggest a layer, but it is weaker evidence than a corresponding log entry.
Changing the header alone will not implement a missing method. Allow describes the resource's supported methods; it is not an authorization setting. RFC 9110 Allow semantics
Repair the form contract without changing writes into GET
A native form defaults to GET when its method is omitted. For a server endpoint designed to accept URL-encoded POST data, make both parts explicit:
<form action="/api/contact" method="post">
<label for="message">Message</label>
<textarea id="message" name="message" required></textarea>
<button type="submit">Send message</button>
</form>
The backend must accept this path, method, and body format. An endpoint expecting JSON needs a matching JavaScript request or server-side support for the native form encoding. Check submit buttons for formaction and formmethod overrides when only one submission path fails. MDN form reference
Do not switch a message creation or signup request to GET merely because GET returns 200. Keep the operation's intended semantics, validation, access controls, and abuse protection. After repairing the route, verify the submitted values and resulting confirmation using the website form testing checklist.
For JavaScript callers, inspect response.ok or the status before displaying success. Fetch can resolve to a Response for HTTP errors such as 405; receiving a response is different from completing the task successfully. Preserve the user's input and show a useful failure state. MDN Fetch error handling
Check redirects and OPTIONS before changing CORS
A successful handler can redirect a POST to a confirmation page that only supports GET. If that redirect preserves POST, the destination may return 405. Inspect each Network entry rather than only the final URL.
For a successful POST followed by a separate confirmation retrieval, a 303 response directs the client to retrieve the destination with GET. A 307 preserves the original method and body. Choose the redirect according to the intended workflow; do not globally replace redirects to hide a method mismatch. MDN 303, MDN 307
For a cross-origin API call, separate the OPTIONS preflight from the actual request. Access-Control-Allow-Methods communicates permitted methods during CORS preflight; it is a different header from Allow. A functioning preflight still needs a working, correctly protected actual endpoint. The CORS troubleshooting guide covers origins, credentials, and browser verification. MDN CORS methods header
A same-origin form does not need a permissive cross-origin policy to repair a missing POST handler. Follow the observed request path before changing response-sharing rules.
Add an HTTP 405 error regression check
Keep a small method contract alongside the deployed route. This example checks a same-origin, read-only preview API: POST accepts text and returns a preview, while GET deliberately returns 405. It does not create a message or send email.
The handler uses standard Request and Response objects. Save it as preview-handler.mjs, and wire handlePreview to /api/preview using your server's routing API. It is a focused example, not a complete public API deployment; apply your normal request-size limits and operational controls.
export async function handlePreview(request) {
const headers = { "Cache-Control": "no-store" };
if (request.method !== "POST") {
return Response.json({ error: "method_not_allowed" }, {
status: 405,
headers: { ...headers, Allow: "POST" },
});
}
const mediaType = (request.headers.get("content-type") ?? "")
.split(";")[0].trim().toLowerCase();
if (mediaType !== "application/json") {
return Response.json({ error: "json_required" }, { status: 415, headers });
}
let body;
try {
body = await request.json();
} catch {
return Response.json({ error: "invalid_json" }, { status: 400, headers });
}
if (typeof body?.text !== "string" || body.text.length > 2000) {
return Response.json({ error: "invalid_text" }, { status: 400, headers });
}
return Response.json({ preview: body.text.trim() }, { headers });
}
The following Node.js 22 script checks the HTTP boundary after deployment. Run it against a test deployment of this preview endpoint. For a real signup, payment, or contact endpoint, use an isolated test account or fixture rather than copying a write probe into production monitoring.
// scripts/check-preview-methods.mjs
import assert from "node:assert/strict";
const origin = process.env.RELEASE_ORIGIN;
if (!origin) throw new Error("Set RELEASE_ORIGIN to the test deployment");
const endpoint = new URL("/api/preview", origin);
const options = { redirect: "manual", signal: AbortSignal.timeout(10_000) };
const rejected = await fetch(endpoint, options);
assert.equal(rejected.status, 405, "GET should remain unsupported");
const allowed = (rejected.headers.get("allow") ?? "")
.split(",").map((method) => method.trim());
assert.deepEqual(allowed, ["POST"], "Unexpected supported methods");
assert.equal((await rejected.json()).error, "method_not_allowed");
const accepted = await fetch(endpoint, {
redirect: "manual",
signal: AbortSignal.timeout(10_000),
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ text: " Launch preview " }),
});
assert.equal(accepted.status, 200, "POST should reach the preview handler");
assert.match(accepted.headers.get("content-type") ?? "", /application\/json/i);
assert.deepEqual(await accepted.json(), { preview: "Launch preview" });
console.log("Preview method contract passed");
Run RELEASE_ORIGIN=https://preview.example.com node scripts/check-preview-methods.mjs after wiring the route. Manual redirect handling makes unexpected redirects fail the asserted status instead of silently testing a different destination. Adapt the expected methods and response contract to your application.
This request check catches route mapping errors, a missing Allow header, and an HTML fallback masquerading as success. It does not exercise the form's event handler. Complete the browser task as well, verify the final UI state, and record the release URL and commit in your website regression testing evidence.
Check the repaired public page with Slop Audit
Once the intended request works, run Slop Audit on the public page. Its static stage records the final document's HTTP status and content type. Review the available metadata, crawl controls, layout, and accessibility evidence, fix remaining findings, and rescan.
Slop Audit does not submit your form, test every API method, or validate Allow and CORS policies. Its browser request-failure evidence is not a complete HTTP error inventory: a 405 response can complete at the network level. Keep the focused method test and task outcome beside the report. Use the console and network debugging guide if the page still displays success despite a rejected request.