http权威指南之三HTTP消息

1、术语inbound,” “outbound,” “upstream,” and “down-stream


2、消息的组成

        start line + header + body(optional)


        The start line and headers are just ASCII text, broken up by lines. Each line ends with
a two-character end-of-line sequence, consisting of a carriage return (ASCII 13) and a

line-feed character (ASCII 10). 


3、消息的语法

        All HTTP messages fall into two types: request messages and response messages.


        Here’s the format for a request message:
        <method> <request-URL> <version>
        <headers>
        <entity-body>


        Here’s the format for a response message (note that the syntax differs only in the
            start line):
        <version> <status> <reason-phrase>
        <headers>
        <entity-body>

4、Start Lines
        All HTTP messages begin with a start line. The start line for a request message says
    what to do. The start line for a response message says what happened.

    Request line
            Request messages ask servers to do something to a resource. The start line for a
    request message, or request line, contains a method describing what operation the
    server should perform and a request URL describing the resource on which to per-
    form the method. The request line also includes an HTTP version which tells the
    server what dialect of HTTP the client is speaking.

    Response line
        Response messages carry status information and any resulting data from an opera-
    tion back to a client. The start line for a response message, or response line, contains
    the HTTP version that the response message is using, a numeric status code, and a
    textual reason phrase describing the status of the operation.

5、Methods
The method begins the start line of requests, telling the server what to do.


    GET: Get a document from the server. 
    HEAD :Get just the headers for a document from the server. No
    POST :Send data to the server for processing. Yes
    PUT :Store the body of the request on the server. Yes
    TRACE: Trace the message through proxy servers to the server. No
    OPTIONS:Determine what methods can operate on a server. No

    DELETE: Remove a document from the server. 

6、Status codes
As methods tell the server what to do, status codes tell the client what happened.


    Overall         range         Defined range Category
    100-199       100-101     Informational
    200-299       200-206      Successful
    300-399       300-305     Redirection
    400-499       400-415     Client error

    500-599       500-505     Server error

    Common status codes
    200     OK Success!             Any requested data is in the response body.
    401     Unauthorized             You need to enter a username and password.
    404     Not Found                 The server cannot find a resource for the requested URL.

7、Reason phrases
The reason phrase is the last component of the start line of the response. It provides
a textual explanation of the status code.  Reason phrases are paired one-to-one with status codes. 

8、Version numbers
    Version numbers appear in both request and response message start lines in the for-
mat HTTP/x.y.   They provide a means for HTTP applications to tell each other what
version of the protocol they conform to.

        Note that version numbers are not treated as fractional numbers. Each number in the
    version (for example, the “1” and “0” in HTTP/1.0) is treated as a separate number. so HTTP/2.22 

    > HTTP/2.3


9、Headers

    HTTP header fields add additional information to request and response messages.
They are basically just lists of name/value pairs.


    General headers
        Can appear in both request and response messages
    Request headers
         Provide more information about the request
    Response headers
        Provide more information about the response
    Entity headers
        Describe body size and contents, or the resource itself
    Extension headers

        New headers that are not defined in the specification

10、Entity Bodies
        The third part of an HTTP message is the optional entity body. Entity bodies are the
payload of HTTP messages. They are the things that HTTP was designed to transport.


































你可能感兴趣的:(http权威指南之三HTTP消息)