当邮件正文为空时,是否应出现Content-Type标头? [英] Should Content-Type header be present when the message body is empty?

查看:208
本文介绍了当邮件正文为空时,是否应出现Content-Type标头?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果没有有效负载正文,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屋!

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