简体   繁体   中英

JSON Parsing Error with HTTP Status Code 204

This is a weird scenario I came across while developing a RESTful API . Whenever I send a HTTP Status Code 204 along with a JSON encoded array to show the message, my REST client ( at this moment, it is a Google Chrome extension ), shows me an error of ' Malformed JSON '. If I change the status code to something else, the client shows the JSON just fine. I'm new-ish to the REST API but this still seems like a weird thing to me.

204 Status Code Explained

The 204 status code means that the request was received and understood, but that there is no need to send any data back.

Why it Occurs

The server has fulfilled the request but does not need to return an entity-body, and might want to return updated metainformation. The response MAY include new or updated metainformation in the form of entity-headers, which if present, SHOULD be associated with the requested variant.The 204 response MUST NOT include a message-body, and thus is always terminated by the first empty line after the header fields.

What it Means

If the client is a user agent, it SHOULD NOT change its document view from that which caused the request to be sent. This response is primarily intended to allow input for actions to take place without causing a change to the user agent's active document view, although any new or updated metainformation SHOULD be applied to the document currently in the user agent's active view.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM