是否有不同的方法来发送 http 响应?
Are there different methods to send a http response?
我们都知道 http 请求有一个方法 (GET/POST/etc)。我想知道是否也有任何特定的 http 响应方法?
服务器向客户端发出 HTTP 响应。响应的目的是向客户端提供它请求的资源,或者通知客户端它请求的动作已经执行;或者通知客户在处理其请求时发生了错误。
HTTP 响应包含:
A status line.
A series of HTTP headers, or header fields.
A message body, which is usually needed.
与在请求消息中一样,每个 HTTP header 后跟一个回车符 return 换行符 (CRLF)。在最后一个 HTTP header 之后,使用一个额外的 CRLF(给出一个空行),然后消息 body 开始。
没有。
方法是HTTP请求消息的属性。它不会出现在响应消息中。
见RFC 7230。
虽然 HTTP 请求包含 方法 来指示请求的语义,但 HTTP 响应包含 状态代码 来指示结果操作。
请参阅下面来自 RFC 7230 的一些相关引用,该文档定义了 HTTP/1.1 的消息语法:
An HTTP message can be either a request from client to server or a response from server to client. Syntactically, the two types of message differ only in the start-line, which is either a request-line (for requests) or a status-line (for responses) [...]
A request-line begins with a method token, followed by a single space (SP
), the request-target, another single space (SP), the protocol version, and ends with CRLF
.
request-line = method SP request-target SP HTTP-version CRLF
The method token indicates the request method to be performed on the target resource. The request method is case-sensitive.
method = token
[...]
The first line of a response message is the status-line, consisting of the protocol version, a space (SP
), the status code, another space, a possibly empty textual phrase describing the status code, and ending with CRLF
.
status-line = HTTP-version SP status-code SP reason-phrase CRLF
The status-code element is a 3-digit integer code describing the result of the server's attempt to understand and satisfy the client's corresponding request. [...]
status-code = 3DIGIT
[...]
我们都知道 http 请求有一个方法 (GET/POST/etc)。我想知道是否也有任何特定的 http 响应方法?
服务器向客户端发出 HTTP 响应。响应的目的是向客户端提供它请求的资源,或者通知客户端它请求的动作已经执行;或者通知客户在处理其请求时发生了错误。 HTTP 响应包含:
A status line.
A series of HTTP headers, or header fields.
A message body, which is usually needed.
与在请求消息中一样,每个 HTTP header 后跟一个回车符 return 换行符 (CRLF)。在最后一个 HTTP header 之后,使用一个额外的 CRLF(给出一个空行),然后消息 body 开始。
没有。
方法是HTTP请求消息的属性。它不会出现在响应消息中。
见RFC 7230。
虽然 HTTP 请求包含 方法 来指示请求的语义,但 HTTP 响应包含 状态代码 来指示结果操作。
请参阅下面来自 RFC 7230 的一些相关引用,该文档定义了 HTTP/1.1 的消息语法:
An HTTP message can be either a request from client to server or a response from server to client. Syntactically, the two types of message differ only in the start-line, which is either a request-line (for requests) or a status-line (for responses) [...]
A request-line begins with a method token, followed by a single space (
SP
), the request-target, another single space (SP), the protocol version, and ends withCRLF
.request-line = method SP request-target SP HTTP-version CRLF
The method token indicates the request method to be performed on the target resource. The request method is case-sensitive.
method = token
[...]
The first line of a response message is the status-line, consisting of the protocol version, a space (
SP
), the status code, another space, a possibly empty textual phrase describing the status code, and ending withCRLF
.status-line = HTTP-version SP status-code SP reason-phrase CRLF
The status-code element is a 3-digit integer code describing the result of the server's attempt to understand and satisfy the client's corresponding request. [...]
status-code = 3DIGIT
[...]