HTTPQUERY
中文

204 No Content

Usage

The 204 No Content status code is returned in response to a POST, PUT, or DELETE operation where no message body is expected. Some servers return a 200 with an empty body and a Content-Length of 0 instead.

A practical use case is the result of a form submission where the user presses a “Save” button. The server commits the changes and relies on the client informing the user of success.

The server must not include a message body in a 204 response. Headers like Cache-Control and ETag are still sent and apply to the document identified by the request.

The related 205 Reset Content status also returns no body but additionally instructs the client to reset the document view (for example, clearing a form after submission). A conditional GET returns a 304 to signal the resource does not need to be retrieved again.

Example

The client posts XML data to the server defining a job. The server responds confirming the data was accepted and the job completed. No content needs to be returned, making the 204 No Content status code appropriate.

Request

POST /job HTTP/1.1
Host: example.com
Content-Type: application/xml
Content-Length: 68

<?xml version="1.0"?>
<job>
  <id>125</id>
  <task>G01</task>
</job>

Response

HTTP/1.1 204 No Content

Code references

.NET

HttpStatusCode.NoContent

Rust

http::StatusCode::NO_CONTENT

Rails

:no_content

Go

http.StatusNoContent

Symfony

Response::HTTP_NO_CONTENT

Python3.5+

http.HTTPStatus.NO_CONTENT

Java

java.net.HttpURLConnection.HTTP_NO_CONTENT

Apache HttpComponents Core

org.apache.hc.core5.http.HttpStatus.SC_NO_CONTENT

Angular

@angular/common/http/HttpStatusCode.NoContent