与上一章对应,一个响应信息的包含部分如下:
Response = Status-Line ; Section 6.1
*(( general-header ; Section 4.5
| response-header ; Section 6.2
| entity-header ) CRLF) ; Section 7.1
CRLF
[ message-body ] ; Section 7.2
其中比较重要的是Status-line行,他由以下部分组成:
Status-Line = HTTP-Version SP Status-Code SP Reason-Phrase CRLF
以请求行不同的是,他把version提到第一个了,接着是Status的Code信息,最后是一个原因解释。Code信息是给程序看得,Reason是给人看的。
状态码一般由一个三位数来决定的,其中,第一位数字决定了错误类型,一共有5种。
1xx表示请求正在进行中
2xx表示请求被接受了
3xx表示请求被重新定向了
4xx表示请求有问题(用户发送的请求有问题)
例如:404表示用户请求了一个不可用的资源
上一章的405,表示用户请求了一个不被允许的方法,但是501就表示,这个方法,服务器没有被实现,对
5xx就表示服务器端的错误。
具体的如下:
Status-Code =
"100" ; Section 10.1.1: Continue
| "101" ; Section 10.1.2: Switching Protocols
| "200" ; Section 10.2.1: OK
| "201" ; Section 10.2.2: Created
| "202" ; Section 10.2.3: Accepted
| "203" ; Section 10.2.4: Non-Authoritative Information
| "204" ; Section 10.2.5: No Content
| "205" ; Section 10.2.6: Reset Content
| "206" ; Section 10.2.7: Partial Content
| "300" ; Section 10.3.1: Multiple Choices
| "301" ; Section 10.3.2: Moved Permanently
| "302" ; Section 10.3.3: Found
| "303" ; Section 10.3.4: See Other
| "304" ; Section 10.3.5: Not Modified
| "305" ; Section 10.3.6: Use Proxy
| "307" ; Section 10.3.8: Temporary Redirect
| "400" ; Section 10.4.1: Bad Request
| "401" ; Section 10.4.2: Unauthorized
| "402" ; Section 10.4.3: Payment Required
| "403" ; Section 10.4.4: Forbidden
| "404" ; Section 10.4.5: Not Found
| "405" ; Section 10.4.6: Method Not Allowed
| "406" ; Section 10.4.7: Not Acceptable
| "407" ; Section 10.4.8: Proxy Authentication Required
| "408" ; Section 10.4.9: Request Time-out
| "409" ; Section 10.4.10: Conflict
| "410" ; Section 10.4.11: Gone
| "411" ; Section 10.4.12: Length Required
| "412" ; Section 10.4.13: Precondition Failed
| "413" ; Section 10.4.14: Request Entity Too Large
| "414" ; Section 10.4.15: Request-URI Too Large
| "415" ; Section 10.4.16: Unsupported Media Type
| "416" ; Section 10.4.17: Requested range not satisfiable
| "417" ; Section 10.4.18: Expectation Failed
| "500" ; Section 10.5.1: Internal Server Error
| "501" ; Section 10.5.2: Not Implemented
| "502" ; Section 10.5.3: Bad Gateway
| "503" ; Section 10.5.4: Service Unavailable
| "504" ; Section 10.5.5: Gateway Time-out
| "505" ; Section 10.5.6: HTTP Version not supported
| extension-code
extension-code = 3DIGIT
Reason-Phrase = *
还不够!! 这些还能够根据需要而被扩展,没准HTTP/1.2又搞出一堆其他的什么出来。然后可是,服务器端并不需要理解所有的Status-Code,尽管,
我们希望如此,如果一个Status-code未被理解,将被解释成x00,例如你来一个532,根本没这玩意儿,将被解释成500.
同样一个响应信息的头域,允许服务器返回附加信息给用户代理,他应该由以下内容组成
response-header = Accept-Ranges ; Section 14.5
| Age ; Section 14.6
| ETag ; Section 14.19
| Location ; Section 14.30
| Proxy-Authenticate ; Section 14.33
| Retry-After ; Section 14.37
| Server ; Section 14.38
| Vary ; Section 14.44
| WWW-Authenticate ; Section 14.47
当然,一个未被识别的响应头域,将被看错信息头域。