Skip to content

405 Method Not Allowed

The URL exists but does not accept the HTTP method you used, like sending POST to an endpoint that only allows GET.

What 405 Method Not Allowed means

The server must include an Allow header listing the methods the resource does support, for example Allow: GET, HEAD.

405 is about the method on a resource the server knows. If the server does not recognise the method at all, 501 Not Implemented fits better.

Common causes

  • Calling an API endpoint with the wrong method, such as POST instead of PUT.
  • A form posting to a static file, which most web servers only serve with GET and HEAD.
  • A route defined for GET only, with no handler for the method you sent.
  • CORS preflight OPTIONS requests that the server does not handle.

How to fix 405 Method Not Allowed

  1. Check the Allow header in the response and use one of the listed methods.
  2. Read the API documentation for the endpoint's method.
  3. Add a handler for the method in your router, or send the request to the correct path.
  4. If a proxy sits in front, check it is not rewriting the URL to a static file.

Headers that go with it

  • Allow

Example response

HTTP/1.1 405 Method Not Allowed
Allow: GET, HEAD
Content-Type: text/plain; charset=utf-8

405 Method Not Allowed

How to check for a 405 response

cURL

# Print only the status code
curl -s -o /dev/null -w "%{http_code}\n" https://example.com/

JavaScript (Node.js)

const res = await fetch("https://example.com/");
if (res.status === 405) {
  console.log(res.status, res.statusText);
}

Python

import requests

res = requests.get("https://example.com/")
if res.status_code == 405:
    print(res.status_code, res.reason)

Go

res, err := http.Get("https://example.com/")
if err != nil {
	log.Fatal(err)
}
defer res.Body.Close()
if res.StatusCode == 405 {
	fmt.Println(res.Status)
}

Specification

405 Method Not Allowed is defined in RFC 9110, section 15.5.6.

  • 501

    Not Implemented

    The server does not support the functionality needed for the request, typically an HTTP method it does not recognise.

  • 404

    Not Found

    The server cannot find anything at this URL. The page may have moved or been deleted, or the link may have a typo.

  • 400

    Bad Request

    The server could not understand the request because something in it is malformed, like broken JSON, bad syntax or invalid headers.

← all 63 HTTP status codes

Type to search posts, tools and projects.

Keyboard shortcuts

Search+Kor/
Go to homegthenh
Go to bloggthenb
Go to projectsgthenp
Go to timelinegthent
Show this help?
Close search or helpesc