As far as the actual situation is concerned , The roles of two computers as clients or servers may be interchanged . But for a communication line , The roles of server and client are clear .HTTP The roles at both ends of the agreement are clear .

        Example of message sending request :
GET /index.htm HTTP/1.1 Host: hackr.jp
       
It's in here ,GET Indicates the type of access server requested ,/index.htm Represents a resource object that requests access , Also called request URI,HTTP/1.1 On behalf of the client HTTP Version number of , Used to prompt the client to use HTTP Protocol function .

        The request message consists of the request method , request URI, Protocol version , The optional request header consists of fields and content entities .

        Example of response message :
HTTP/1.1 200 OK Date : Tue ,10 Jul 2012 06:50:15 GMT Content - Length :362
Content - Type : text/html <html> ... </html>
        there HTTP/1.1 Indicates the server HTTP Version number of ,OK Is a reason statement , The next line is response time , Write the main body of the resource entity in a blank line below .

        

       
HTTP Agreement passed URI Locate resources on the Internet , because URI Characteristics of , Resources from any location on the Internet can be accessed , If you do not access a specific resource, but make a request to the server itself , Can use *
To replace URI.

HTTP method :

        GET

         Get the resources of the server

        It is worth noting that : The specified resource must be resolved on the server side before it can return a response , If the request is text , Then return as is , If it's a program , Then the output result is returned .

        POST

        The body used to transfer the entity .

        GET You can also transfer the body of an entity , However, it is generally used POST Operate , because POST The main purpose of is not to get the main content of the response .

        PUT

        Used to transfer files to the server .

        General websites do not support PUT, because PUT Authentication is not supported , Very dangerous .

        DELETE

        Used to delete the resources of the server .

        and PUT equally , General websites do not support .

        HEAD

        Get resource related information .

        And GET Method similarity , however HEAD Method does not return the message body , Mainly used to confirm URI Validity of and date and time of resource update .

        OPTIONS

        Ask for support .

        Used to query for requests URI Specifies the method supported by the resource .

        TRACE

        Used to understand the process of transmission in the physical layer , How many routers have you passed , How did you handle it .

        CONNECT

        Connection agent using tunneling protocol .

HTTP Connection of :

         Persistent connection :

        As long as either end does not explicitly propose to disconnect , Then keep TCP Connection status of .

        stay HTTP/1.1 in , All connections are persistent by default .

        Pipelining :

        Persistent connections make pipelining possible .

        That is, the next request is sent directly without waiting for the response of the previous request .

        In that case , Multiple requests can be sent in parallel at the same time , And the more requests , The more obvious the time difference is .

Cookie Management status

        HTTP Stateless :

    HTTP Is a protocol that does not save state , Stateless protocol , It does not persist any sent request or response .

        HTTP The state in which advantages are not saved : Lightweight , Able to handle a large number of transactions quickly , Ensure the scalability of the protocol .

        use Cookie:

        Cookie One of the response messages sent from the server is called Set-Cookie Header field information for , Notify client to save Cookie.

        When writing a client to send a request , The client will automatically Cookie Add to the request message .

       
When the server finds the message sent from the client Cookie Time , Will check which client sent the request , Then compare the records on the server , Verify , You can get the previous status information .

        Reference books :《 graphic HTTP》 Ueno Xuan Write Yu Junliang translate

Technology