HTTP post请求中是否必须使用Content-Type? [英] Is Content-Type mandatory in HTTP post request?

查看:1462
本文介绍了HTTP post请求中是否必须使用Content-Type?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否为字段:


Content-Type

Content-Type


$ b我执行HTTP请求时必须$ b

mandatory when I perform an HTTP request?

推荐答案

不,这不是强制性的。根据 HTTP 1.1规范

No, it's not mandatory. Per the HTTP 1.1 specification:


包含实体主体的任何HTTP / 1.1消息应该包括定义该主体的媒体类型的Content-Type头字段。当且仅当媒体类型不是由Content-Type字段给出时,接收者可以尝试通过检查其内容和/或用于标识资源的URI的名称扩展来猜测媒体类型。如果媒体类型仍然未知,收件人应该将其视为application / octet-stream类型。

Any HTTP/1.1 message containing an entity-body SHOULD include a Content-Type header field defining the media type of that body. If and only if the media type is not given by a Content-Type field, the recipient MAY attempt to guess the media type via inspection of its content and/or the name extension(s) of the URI used to identify the resource. If the media type remains unknown, the recipient SHOULD treat it as type "application/octet-stream".

这就是说,显然如果省略Content-Type标题,服务器很难准确地解释您发送的数据,因此不建议这样做。

That said, it's obviously going to be hard for the server to accurately interpret the data you're sending if you omit the Content-Type header, so it's not recommended to do so.

这篇关于HTTP post请求中是否必须使用Content-Type?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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