HTTP规范中关于请求/响应中的message-body和entity-body
请求
响应
并不是所有的请求响应消息中都包含内容:message body或者entity body。
大多数请求消息中不包含消息体。
在有些请求的响应中不包含响应内容。
比如,如果在请求消息中包含If-Modified-Since头字段,如:If-Modified-Since: Sat, 29 Oct 2014 19:43:31 GMT,如果被请求的资源在这个指定的时间之后都没有被修改过,将返回一个304 (not modified),响应消息中不包含消息体部分,被请求的资源内容不会传输给客户端。
即便是在响应消息中,也可能不包含响应内容。
请求响应消息中是否包含消息体跟请求方式,如GET,POST等,请求响应中的header头部字段,是否有缓存等等。当然也看是否有数据需要进行传输。
message-body
message-body = entity-body
| <entity-body encoded as per Transfer-Encoding>
从这里的定义来看,message-body和entity-body基本上没什么区别。
entity-body
message-body和entity-body的区别
message-body和entity-body的区别在于消息中是否应用了transfer-coding,即在响应或请求消息中是否包含Transfer-Encoding通用头部。
来自https://tools.ietf.org/html/rfc2616的引用:
写道
The message-body (if any) of an HTTP message is used to carry the
entity-body associated with the request or response. The message-body
differs from the entity-body only when a transfer-coding has been
applied, as indicated by the Transfer-Encoding header field (section
14.41).
message-body = entity-body
| <entity-body encoded as per Transfer-Encoding>
Transfer-Encoding MUST be used to indicate any transfer-codings
applied by an application to ensure safe and proper transfer of the
message. Transfer-Encoding is a property of the message, not of the
entity, and thus MAY be added or removed by any application along the
request/response chain. (However, section 3.6 places restrictions on
when certain transfer-codings may be used.)
The rules for when a message-body is allowed in a message differ for
requests and responses.
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. 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. 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.
For response messages, whether or not a message-body is included with
a message is dependent on both the request method and the response
status code (section 6.1.1). All responses to the HEAD request method
MUST NOT include a message-body, even though the presence of entity-
header fields might lead one to believe they do. All 1xx
(informational), 204 (no content), and 304 (not modified) responses
MUST NOT include a message-body. All other responses do include a
message-body, although it MAY be of zero length.
entity-body associated with the request or response. The message-body
differs from the entity-body only when a transfer-coding has been
applied, as indicated by the Transfer-Encoding header field (section
14.41).
message-body = entity-body
| <entity-body encoded as per Transfer-Encoding>
Transfer-Encoding MUST be used to indicate any transfer-codings
applied by an application to ensure safe and proper transfer of the
message. Transfer-Encoding is a property of the message, not of the
entity, and thus MAY be added or removed by any application along the
request/response chain. (However, section 3.6 places restrictions on
when certain transfer-codings may be used.)
The rules for when a message-body is allowed in a message differ for
requests and responses.
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. 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. 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.
For response messages, whether or not a message-body is included with
a message is dependent on both the request method and the response
status code (section 6.1.1). All responses to the HEAD request method
MUST NOT include a message-body, even though the presence of entity-
header fields might lead one to believe they do. All 1xx
(informational), 204 (no content), and 304 (not modified) responses
MUST NOT include a message-body. All other responses do include a
message-body, although it MAY be of zero length.
相关推荐
请求消息结构为:Full-Request = Request-Line *(General-Header | Request-Header | Entity-Header) CRLF [Entity-Body]。请求消息示例包括 GET 请求行、头域和实体。 响应消息结构类似于请求消息,但是状态行由...
- **HTTP Message (HTTP消息)**:包括请求消息和响应消息两种类型。 - **Start Line (起始行)**:请求行或状态行。 - **Message Header (消息头)**:包含各种元数据信息。 - **Message Body (消息体)**:携带的实际...
- **实体(Entity)**: 请求或响应中携带的有效载荷信息。实体包括元信息和内容两部分,元信息通过实体头域(entity header fields)进行描述。 #### 2. HTTP/1.1的关键特性 - **状态无关(Stateless)**: HTTP协议设计...
消息里是否有消息体的规则对请求和响应是不同的。请求的消息头里的 Content-Length 或者 Transfer-Encoding 报头域决定了在请求里是否存在消息体。如果文档规定了请求方法不能发送实体主体,那么请求中就不能有消息...
- **实体(entity)**:请求或响应中的有效载荷,包含元信息(entity-header)和内容(entity-body)。 - **表现形式(representation)**:通过内容协商选择的响应实体的具体形式。 **HTTP 1.1的改进点** - **...
实体提供者(Entity Providers)包括消息体读取器(MessageBodyReader)和消息体写入器(MessageBodyWriter),它们负责处理HTTP消息体的序列化和反序列化。此外,还有上下文提供者(Context Providers)用于处理...
本篇文章主要会介绍nginx中请求的接收流程,包括请求头的解析和请求体的读取流程。 首先介绍一下rfc2616中定义的http请求基本格式: Request = Request-Line *(( general-header | request-header | entity-...
在Java编程环境中,发送短信至指定手机主要涉及网络通信和HTTP请求的知识。下面将详细讲解这一过程中的关键技术和步骤。 一、HTTP请求基础 HTTP(超文本传输协议)是互联网上应用最为广泛的一种网络协议,用于从Web...
在Java编程中,Apache HttpClient库是一个非常常用的工具,用于发送HTTP请求。本文主要讨论如何使用HttpClient发送JSON格式和普通参数类型的POST请求。首先,我们来看一下所需的Maven依赖。 ```xml <groupId>...
- **缓存(Cache)**:用于存储HTTP响应的系统,目的是减少未来的网络流量和响应时间。 - **缓存策略**:控制消息的存储、恢复和删除。 - **缓存位置**:任何客户端或服务器都可以包含缓存。 #### 三、HTTP消息格式...
上述代码中,`execute`方法会发送请求并返回一个`CloseableHttpResponse`对象,其中包含了服务器的响应状态和响应实体。`getStatusLine()`方法返回HTTP状态码,如200表示成功。`HttpEntity`对象代表了响应体,可以...
为了便于理解,我们可以将这些头部字段归纳为两大类:请求头部字段和响应头部字段。 ### Requests 部分 #### 请求头部字段详解 ##### Accept - **解释**:客户端能够接收的内容类型。 - **示例**:`Accept:text/...
- **实体(Entity)**:实体是请求或响应的有效负载信息,包含了实体头域(entity header fields)和实体主体(entity body)两部分。 #### 2. HTTP/1.1 特性详解 **2.1 分布式与协作式系统** HTTP协议的设计初衷是为了...
通信过程中,消息的传送类似于MIME格式,消息单元称为消息(message),分为请求(request)和响应(response)两大类。 在HTTP1.1版本中,相较于之前的HTTP/1.0版本,主要改进在于增加了对持久连接、分层代理、...
public ResponseEntity<Employee> createEmployee(@RequestBody Employee employee) { // 业务逻辑 } } ``` #### 数据绑定 Spring MVC提供了强大的数据绑定机制,可以自动将请求参数与控制器方法参数进行绑定。 ...
在Spring Boot框架中,文件上传和下载是常见的功能需求,特别是在构建Web应用程序时。Spring Boot提供了简洁、易于使用的API来处理这些操作。本篇将详细阐述如何实现Spring Boot中的文件上传与下载功能。 首先,...
Swagger 是一个流行的API文档生成和测试工具,它允许开发者通过注解轻松地在Java代码中定义RESTful...通过这种方式,开发者能够快速生成规范的API文档,并且可以直接在Swagger UI中测试接口,提高开发效率和API的质量。
`HttpClient`提供了一系列接口和实现类,用于构建、发送HTTP请求以及处理响应。在使用`HttpClient`之前,我们需要了解其基本结构和核心组件: - **HttpClient**:是一个接口,定义了发送HTTP请求的基本方法。 - **...
- **消息(Message)**:SIP的核心组成部分,用于传输请求和响应。 - **头域(Header Fields)**:提供关于消息的信息,如消息类型、发送者信息等。 - **消息体(Body)**:携带会话描述和其他相关信息。 #### 六、关键...