Basic knowledge of HTTP protocol Request Response JavaWeb

reference

Xie Xiren's Seventh Edition of Computer Networks (I didn't learn HTTP last semester)

Dark Horse Programmer JavaWeb Course (After watching this semester, I will summarize it by the way)

Organized by me

HTTP:

 

 

(concepts and features, must understand) 

* Concept (what is HTTP):

        Hyper Text Transfer Protocol  Hypertext Transfer Protocol

        HTTP is the hypertext transfer protocol, so what is the transfer protocol?

* Transmission protocol: defines the format for exchanging data when the client and server communicate

* Features:

        1. High-level protocol based on TCP/IP

        2. Default port number: 80

        3. Based on the request/response model: one request corresponds to one response

        4. Stateless: Each request is independent of each other and cannot exchange data

* historic version:

        * 1.0: A new connection will be established for each request response

        * 1.1: multiplex connection

(The following is the lesson plan taught by the black horse class)

 Request:

        Client sends message to server

(important, need to be familiar with)

Request message data format

        1. Request line

        2. Request header: The client browser tells the server some information

        3. Request a blank line

        4. Request body (text):

1. Request line

        Format:

                Request method Request url Request protocol/version

                GET           /login.html      HTTP/1.1

        * Request methods (7 types): GET and POST are commonly used

                                 

2. Request header: The client browser tells the server some information

       Format:

                Request header name: request header value

        * Common request headers:

                1. User-Agent: The browser tells the server that I visit the browser version information you use

                        * The header information can be obtained on the server side to solve browser compatibility issues

                2. Referer:http://localhost/login.html

                        * Tell the server, where did I (the current request) come from?

                        * Function: 1. Anti-leech 2. Statistical work

                                

3. Request a blank line:

        Blank lines are used to separate the request header and request body of the POST request.

4. Request body (text):

        * Encapsulate the request parameters of the POST request message

String format:

 Let's go to the browser to verify

Response:

        Server sends message to client

(important, need to be familiar with)

* Data Format:

        1. Response line:

        2. Response header:      

        3. Respond to blank lines:

        4. Response body: transmitted data:


        1. Response line:

              Composition: Protocol/Version Response Status Code Status Code Description
            
                  Response Status Code: The server tells the client browser a status of this request and response.
                  
                 Classification:
                    1. 1xx: The server received the message from the client, but did not complete the acceptance. After waiting for a period of time, it sent 1xx multi-status codes.
                    2. 2xx: Success. Rep: 200
                    3. 3xx: Redirection. Representatives: 302 (redirection), 304 (access cache)
                    4. 4xx: client error.
                        * stands for: * 404 (the request path does not have a corresponding resource) 
                                     * 405: the request method does not have a corresponding doXxx method
                    5. 5xx: server-side error. Representative: 500 (An exception occurred inside the server)

        2. Response header:

            1. Format: Header name: Value
            2. Common response headers:
                1. Content-Type: The server tells the client the data format and encoding format of the response body
                2. Content-disposition: The server tells the client in what format to open the response body Data
                    * Value:
                        * in-line: Default value, open in the current page
                        * attachment; filename=xxx: Open the response body as an attachment. Download Document


        3. Respond to empty lines


        4. Response body: transmitted data

Go to the browser to verify 

Guess you like

Origin blog.csdn.net/m0_52559040/article/details/123482283