简体   繁体   English

GET请求上的Content-Type标头是否具有惯常的语义含义?

[英]Does a Content-Type header on a GET request ever cary semantic meaning?

So I've been embroiled in a discussion as to the appropriate interpretation of Content-Type headers in a GET request. 因此,我陷入了关于GET请求中Content-Type标头的适当解释的讨论。 I plan on discarding the value of the Content-Type header on all GET requests to the service, as while it is permissible for a GET request to contain a body, server semantics for a GET request are restricted such that the body has no semantic meaning to the request. 我计划在对服务的所有GET请求上丢弃Content-Type标头的值,因为虽然GET请求可以包含主体,但是GET请求的服务器语义受到限制,因此主体没有语义的要求。

So does the Content-Type of a GET request, which may or may not contain a message body, ever cary semantic meaning? 那么,包含或不包含消息正文的GET请求的Content-Type会一直带有语义含义吗?

Can I safely discard it, or is there something I am overlooking? 我可以安全地丢弃它吗,或者我有什么地方可以忽略?

The Content-Type of a GET request isn't useful and typically is not sent. GET请求的Content-Type无效,通常不会发送。 As you state, if there is no content the type specified is irrelevant. 如您所述,如果没有内容,则指定的类型无关紧要。

Conversely, the Accept header tells you what the client expects in return. 相反, Accept标头告诉您客户期望得到的回报。

RFC 2616 Section 4.3 states: RFC 2616第4.3节规定:

The presence of a message-body in a request is signaled by the inclusion of a Content-Length or Transfer-Encoding header field in the request's message-headers. 通过在请求的消息头中包含Content-Length或Transfer-Encoding头字段,可以指示请求中消息主体的存在。 A message-body MUST NOT be included in a request if the specification of the request method (section 5.1.1) does not allow sending an entity-body in requests. 如果请求方法的规范(第5.1.1节)不允许在请求中发送实体,则消息体不得包含在请求中。 A server SHOULD read and forward a message-body on any request; 服务器应根据任何请求读取并转发消息正文; if the request method does not include defined semantics for an entity-body, then the message-body SHOULD be ignored when handling the request. 如果请求方法不包括为实体主体定义的语义,则在处理请求时应忽略消息主体。

A GET request does not define any semantics for a message body, thus the message body, and its accompanied Content-Type if present, are to be ignored. GET请求没有为消息主体定义任何语义,因此将忽略消息主体及其附带的Content-Type如果存在)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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