HTTP

HTTP 204 No Content vs 405 Method Not Allowed

HTTP 204 (No Content) is a 2xx Success response, while 405 (Method Not Allowed) is a 4xx Client Error response. 204 indicates that the server successfully processed the request but is not returning any content. Common for DELETE operations and form submissions that don't need a response body. In contrast, 405 means that the HTTP method is not allowed for the requested resource. The response includes an Allow header listing valid methods.

描述

The server successfully processed the request but is not returning any content. Common for DELETE operations and form submissions that don't need a response body.

何时出现

After DELETE requests, PUT updates where no body is needed, or CORS preflight responses.

如何修复

No fix needed. The action was successful; there is simply no content to return.

描述

The HTTP method is not allowed for the requested resource. The response includes an Allow header listing valid methods.

何时出现

When sending POST to a read-only endpoint, or DELETE to a non-deletable resource.

如何修复

Check the Allow response header for supported methods. Use the correct HTTP method.

主要区别

1.

204 is a 2xx Success response, while 405 is a 4xx Client Error response.

2.

HTTP 204: The server successfully processed the request but is not returning any content. Common for DELETE operations and form submissions that don't need a response body.

3.

HTTP 405: The HTTP method is not allowed for the requested resource. The response includes an Allow header listing valid methods.

4.

You encounter 204 when after DELETE requests, PUT updates where no body is needed, or CORS preflight responses.

5.

You encounter 405 when when sending POST to a read-only endpoint, or DELETE to a non-deletable resource.

何时使用哪个

For 204 (No Content): No fix needed. The action was successful; there is simply no content to return. For 405 (Method Not Allowed): Check the Allow response header for supported methods. Use the correct HTTP method.

了解更多