json 请求负载和请求正文
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22069844/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Request payload and request body
提问by Ankur Garg
I am learning about REST , while making a POST Call I send a request payload which can be of XML or JSON format . What I wanted to know is whether Request Payload and request body mean the same thing ?
我正在学习 REST,在进行 POST 调用时,我发送了一个请求有效负载,它可以是 XML 或 JSON 格式。我想知道的是 Request Payload 和 request body 是否是同一个意思?
采纳答案by Satyam
Definition of: payload : The "actual data" in a packet or file minus all headers attached for transport and minus all descriptive meta-data. In a network packet, headers are appended to the payload for transport and then discarded at their destination.
定义: 有效载荷:数据包或文件中的“实际数据”减去所有附加用于传输的标头并减去所有描述性元数据。在网络数据包中,标头被附加到有效载荷以进行传输,然后在目的地被丢弃。
Edit: In Http protocol, an http packet has http headers and http payload.So payload section of http packet may or may not have a body depending upon the type of request (e.g. POST vs GET). So payload and body are not the same thing.
编辑:在 Http 协议中,http 数据包具有 http 标头和 http 有效负载。因此,http 数据包的有效负载部分可能有也可能没有正文,具体取决于请求的类型(例如 POST 与 GET)。所以有效载荷和身体不是一回事。
回答by Dejell
Payload is the "wrapper" to the body
有效载荷是身体的“包装器”
Payload is something one carries. A paperboy's payload is a pile of newspapers and a HTTP POST request's payload is whatever comes in the "body".
有效载荷是一个人携带的东西。报童的有效载荷是一堆报纸,而 HTTP POST 请求的有效载荷是“正文”中的任何内容。
回答by Maggyero
HTTP client/server messagingdescribed in RFC 7230: Hypertext Transfer Protocol (HTTP/1.1): Message Syntax and Routingdefines resource metadata and representation metadata, and makes a distinction between a payloadbody and messagebody (because a message body can be encoded for transfer with the encoding defined in the Transfer-Encodingheader field):
RFC 7230: Hypertext Transfer Protocol (HTTP/1.1): Message Syntax and Routing 中描述的HTTP 客户端/服务器消息传递定义了资源元数据和表示元数据,并区分了有效载荷正文和消息正文(因为消息正文可以编码为使用Transfer-Encoding标头字段中定义的编码进行传输):
Most HTTP communication consists of a retrieval request (GET) for a representation of some resource identified by a URI. In the simplest case, this might be accomplished via a single bidirectional connection (===) between the user agent (UA) and the origin server (O).
request > UA ======================================= O < responseA client sends an HTTP request to a server in the form of a request message, beginning with a request-line that includes a method, URI, and protocol version (Section 3.1.1), followed by header fields containing request modifiers, client information, and representation metadata(Section 3.2), an empty line to indicate the end of the header section, and finally a message body containing the payload body(if any, Section 3.3).
A server responds to a client's request by sending one or more HTTP response messages, each beginning with a status line that includes the protocol version, a success or error code, and textual reason phrase (Section 3.1.2), possibly followed by header fields containing server information, resource metadata, and representation metadata(Section 3.2), an empty line to indicate the end of the header section, and finally a message body containing the payload body(if any, Section 3.3).
大多数 HTTP 通信包含一个检索请求 (GET),用于表示由 URI 标识的某些资源。在最简单的情况下,这可能通过用户代理 (UA) 和源服务器 (O) 之间的单个双向连接 (===) 来完成。
request > UA ======================================= O < response客户端以请求消息的形式向服务器发送 HTTP 请求,以包含方法、URI 和协议版本的请求行开头(第 3.1.1 节),然后是包含请求修饰符、客户端信息的标头字段, 和表示元数据(第 3.2 节),一个空行表示头部分的结尾,最后是一个包含有效负载主体的消息体(如果有,第 3.3 节)。
服务器通过发送一个或多个 HTTP 响应消息来响应客户端的请求,每个响应消息都以状态行开头,其中包括协议版本、成功或错误代码和文本原因短语(第 3.1.2 节),可能后跟标题字段包含服务器信息、资源元数据和表示元数据(第 3.2 节),一个指示标头部分结束的空行,最后是一个包含有效负载正文的消息正文(如果有,请参见第 3.3 节)。
Later in that RFC, the HTTP message format(for both request messages or response messages) is summed up:
在该 RFC 的后面,总结了HTTP 消息格式(对于请求消息或响应消息):
Start line<CR><LF>
Header fields<CR><LF>
<CR><LF>
Message body (optional)
where <CR> is the carriage return character and <LF> the line feed character.
其中 <CR> 是回车符,<LF> 是换行符。
The abstractof RFC 7231: Hypertext Transfer Protocol (HTTP/1.1): Semantics and Contentgives a definition of a payload:
RFC 7231: Hypertext Transfer Protocol (HTTP/1.1): Semantics and Content的摘要给出了有效载荷的定义:
The Hypertext Transfer Protocol (HTTP) is a stateless application-level protocol for distributed, collaborative, hypertext information systems. This document defines the semantics of HTTP/1.1 messages, as expressed by request methods, request header fields, response status codes, and response header fields, along with the payload of messages (metadata and body content)and mechanisms for content negotiation.
超文本传输协议 (HTTP) 是一种用于分布式协作超文本信息系统的无状态应用程序级协议。本文档定义了 HTTP/1.1 消息的语义,如请求方法、请求头字段、响应状态代码和响应头字段,以及消息的有效负载(元数据和正文内容)和内容协商机制。
So we can conclude that an HTTP payloadis made of:
因此,我们可以得出结论,HTTP有效负载由以下部分组成:
- metadatacontained in the header-fields;
- datacontained in the message body (before being transfer encoded).
- 包含在标头字段中的元数据;
- 包含在消息正文中的数据(在传输编码之前)。

