什么内容类型应该使用204无响应? [英] What Content-Type should a 204 No Response use?

查看:113
本文介绍了什么内容类型应该使用204无响应?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在构建RESTful HTTP服务时,响应是否为204 No Content(例如在Consumer发出DELETE请求之后),响应包含哪些Content-Type?

When building a RESTful HTTP service, and a Response is given with a 204 No Content (e.g. after the Consumer issues a DELETE Request), what Content-Type should the Response include?

是否应该省略?
是否有首选的内容类型?
它应该与同一资源的GET请求的内容类型相同吗?
这无关紧要吗?

Should it be omitted? Is there a preferred Content-Type? Should it be the same Content-Type of a GET Request to the same Resource? Does it not matter whatsoever?

推荐答案

你有 Content-Type 当你有内容时,即使它是可选的:

You have Content-Type when you have content and even then it's optional:


包含实体主体的任何HTTP / 1.1消息应该包含一个Content-Type标题字段,用于定义该主体的媒体类型。

Any HTTP/1.1 message containing an entity-body SHOULD include a Content-Type header field defining the media type of that body.

(来自 RFC2616,§7.2.1,请注意使用SHOULD)。

(from RFC2616, §7.2.1, please note the use of SHOULD).

由于没有内容,因此没有理由指定 Content-Type 标题。

Since there is no content, then there is no reason to specify a Content-Type header.

这篇关于什么内容类型应该使用204无响应?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆