当邮件正文为空时,是否应出现Content-Type标头? [英] Should Content-Type header be present when the message body is empty?
问题描述
如果没有有效负载正文,HTTP请求或响应中是否存在 Content-Type标头
?
Should the Content-Type header
be present in an HTTP request or response when there is no payload body?
在这种情况下,HTTP标头的正确组合是否没有 Content-Type
和 Content-Length
0,或当消息缺少正文时, Content-Type
根本不存在?
Is the correct combination of HTTP headers in this case to have no Content-Type
and a Content-Length
of 0, or should the Content-Type
not be present at all when the message lacks a body?
推荐答案
RFC 7231 说:
生成包含有效负载主体的消息的发件人应该在该消息中生成一个Content-Type头字段[...]
A sender that generates a message containing a payload body SHOULD generate a Content-Type header field in that message [...]
因此,如果您生成不的消息,则不会明确说明该怎么做有一个有效负载体,但似乎暗示在这种情况下不发送Content-Type标头是合适的。
So it doesn't say explicitly what to do if you're generating a message that doesn't have a payload body, but it certainly seems implied that not sending a Content-Type header would be appropriate in that case.
Content-Length:0就是你如何除非你使用像分块编码这样的东西,否则会向接收者说明没有正文。
Content-Length: 0 is how you would indicate to the receiver that there will be no body, unless you're using something like chunked encoding.
这篇关于当邮件正文为空时,是否应出现Content-Type标头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!