What Is a 405 Status Code?

The method received in the request-line is known by the origin server but not supported by the target resource.

The origin server MUST generate an Allow header field in a 405 response containing a list of the target resource’s currently supported methods.

A 405 response is cacheable by default; i.e., unless otherwise indicated by the method definition or explicit cache controls1.


405 CODE REFERENCES

Rails HTTP Status Symbol :method_not_allowed

Go HTTP Status Constant http.StatusMethodNotAllowed

Symfony HTTP Status Constant Response::HTTP_METHOD_NOT_ALLOWED

Python2 HTTP Status Constant httplib.METHOD_NOT_ALLOWED

Python3+ HTTP Status Constant http.client.METHOD_NOT_ALLOWED

Python3.5+ HTTP Status Constant http.HTTPStatus.METHOD_NOT_ALLOWED

.NET HttpStatusCode.MethodNotAllowed

Rust http::StatusCode::METHOD_NOT_ALLOWED

Java java.net.HttpURLConnection.HTTP_BAD_METHOD

Apache HttpComponents Core org.apache.hc.core5.http.HttpStatus.SC_METHOD_NOT_ALLOWED

Angular @angular/common/http/HttpStatusCode.MethodNotAllowed

405 status code example

Here is an example of a request and response that would result in a 405 Method Not Allowed status code:

Request

Request:
POST /users HTTP/1.1
Host: example.com
Content-Type: application/json

{"name": "John Doe", "email": "[email protected]"}

Response

HTTP/1.1 405 Method Not Allowed
Allow: GET, HEAD
Content-Type: text/html

<!DOCTYPE html>
<html>
<head>
<title>405 Method Not Allowed</title>
</head>
<body>
<h1>Method Not Allowed</h1>
<p>The method POST is not allowed for the requested resource.</p>
</body>
</html>

In this example, the client is attempting to create a new user by sending a POST request to the /users endpoint. However, the server does not support the POST method for this endpoint, and instead only allows GET and HEAD requests. Therefore, the server responds with a 405 status code and includes an “Allow” header in the response indicating which methods are allowed for this resource. The response also includes a brief explanation of the error in the response body.

What causes a 405 status code?

A 405 Method Not Allowed status code is returned by a server when a client attempts to use an HTTP method that is not allowed for the requested resource.

This error can occur for several reasons, such as:

  • The client is attempting to use an HTTP method that the server does not support for the requested resource. For example, the server may only allow GET requests, but the client is attempting to use a POST request.
  • The client is attempting to use an HTTP method that the server does not support at all. For example, the server may only support GET and POST requests, but the client is attempting to use a PUT request.
  • The client is attempting to use an HTTP method that is not allowed for the current authentication credentials or permissions. For example, a user may be trying to update a resource for which they do not have the necessary permissions.

In general, the 405 status code indicates that the client needs to use a different HTTP method or modify the request in some way to access the requested resource.

How to fix a 405 status code

To fix a 405 Method Not Allowed status code, you need to modify the request to use an HTTP method that is allowed for the requested resource. Here are some steps you can take:

  1. Check the documentation or API reference for the resource you are trying to access to see which HTTP methods are allowed.
  2. Modify the request to use one of the allowed HTTP methods. For example, if the server only allows GET requests, you need to modify your request to use the GET method.
  3. Double-check the syntax and structure of the request to make sure that it conforms to the expected format for the HTTP method you are using.
  4. If you are still getting a 405 error, check your authentication credentials or permissions to make sure that you have the necessary privileges to access the requested resource.
  5. If the problem persists, contact the server administrator or support team for further assistance.

In some cases, the server may include an “Allow” header in the response to indicate which HTTP methods are allowed for the requested resource. This can be useful in identifying which methods you can use to access the resource.

Additional resources


Return to List of HTTP Status Codes

TO TOP