What Does a 405 Method Not Allowed Error Mean?
The HTTP protocol uses what is called methods in order to determine which actions should take place on a web server. There are a variety of HTTP methods, however a few examples include:
- GET: Retrieves information from the web server that is defined by a specific URL
- POST: Post information to the web server such as a comment on a forum.
- PUT: Create or replace a resource based on the data the client submits to the web server. (e.g creating a new web page or updating an existing one)
- DELETE: Deletes the resource from the web server associated with a specific URL.
HTTP methods can be configured on the web server to determine which objects should be allowed / disallowed to use particular methods. If a method itself is not allowed throughout a site, this will return a HTTP 501 error.
However in the case of 405 method not allowed, this error indicates that the web server is configured in a way that does not allow you to perform that action for a particular URI. For instance, a website’s static image files will have the request method set to GET only and will disallow the POST method.
405 Error Example
To demonstrate a simple 405 method not allowed example, we can use a cURL command within the terminal. This example replicates a sample POST request to a resource that only accepts GET requests as can be seen by the image below.
Now if we attempt to pass the HTTP POST method for the same resource via cURL with:
curl -X POST https://cdn.keycdn.com/img/cdn-fast.svg
We receive the response:
<html> <head><title>405 Not Allowed</title></head> <body bgcolor="white"> <center><h1>405 Not Allowed</h1></center> <hr><center>nginx</center> </body> </html>
This demonstrates that the resource will solely allow the GET method thus throwing an error for other methods that make a request for the same URL.
How You Might See a 405 Method Not Allowed Error
This error is primarily displayed as 405 Method Not Allowed, however there are a couple of other slight variations the web server may display such as:
- HTTP 405
- Error 405
- (405) Method Not Allowed
Although the message may slightly differ, they all mean the same thing – the HTTP method used is currently not allowed for the specific web asset being requested from the web server.
Why Did I Receive a 405 Error?
In the case that a 405 method not allowed error occurs, it may be due to certain scripts you are trying to run. Some ISP’s do not allow particular scripts or the necessary POST method to be run on their servers which will therefore return a status code 405. Otherwise, there may be an issue with the web server not being configured properly to accept the appropriate request methods.