Introduction to the

HTTP (HyperText Transfer Protocol) is an application layer transmission Protocol based on TCP. Simply speaking, it is a rule for data transmission between the client and the server.

Note: The roles of client and server are not fixed. One side acts as client and may also act as server on a request. It depends on the originator of the request. The HTTP protocol belongs to the application layer and is based on the transport layer protocol TCP. The client establishes a TCP connection with the server and invokes TCP by accessing the Socket interface to send HTTP requests and receive HTTP responses.

HTTP is a stateless protocol. HTTP itself will not persist the sent request and corresponding communication status. The goal is to keep the HTTP protocol simple, so that a large number of transactions can be processed quickly and efficiently. When a client requests a service from a server, it simply passes the request method and path. The commonly used request methods are GET, HEAD and POST. Each method specifies a different type of contact between the client and the server. Because HTTP protocol is simple, the HTTP server program size is small, so the communication speed is very fast.

HTTP URL

HTTP is a stateless protocol that is based on the request and response mode and exists at the transport layer. It is usually based on TCP connections. An HTTP URL is a special type of URI that contains the path used to locate and search a network resource. The format is as follows:

http://host[':'port][abs_path]
Copy the code

HTTP: uses HTTP to locate network resources. Host indicates a valid Internet host domain name or IP address. Port Specifies a port. If default, the default is port 80. Abs_path represents the URL of the requested resource. If nothing is written, the browser adds a ‘/’ as the initial path address.

HTTP Request

As shown below, an HTTP request consists of three parts: the request line, the request header, and the request body (data).

The following figure shows a request message:

HTTP Request methods include: GET: requests to obtain the resources identified by request-URI. POST: adds new data to the resource identified by the request-URI. HEAD: a response message header to Request a resource identified by request-URI; PUT: Requests the server to store or modify a resource and uses request-URI as its identity. DELETE: requests the server to DELETE the resource identified by request-uri. TRACE: The request server sends back the received request information for testing or diagnosis. CONNECT: reserved for future use; OPTIONS: Queries server performance, or queries OPTIONS and requirements related to resources. GET and POST are the most common HTTP methods, and most current browsers support only GET and POST.

② is the URL address corresponding to the request, which together with the Host attribute of the packet header constitutes a complete request URL, and ③ is the protocol name and version number. ①, ② and ③ constitute the HTTP request status line. The request line consists of request Method, URL field and HTTP Version. Generally, the request line defines the request mode and address of the request, as well as the HTTP protocol Version followed, for example:

GET/example. HTTP / 1.1 HTML (CRLF)Copy the code

④ Is an HTTP header. The header contains several attributes in the format of “Attribute Name: Attribute value”. The server obtains information about the client based on these attributes.

⑤ is a newspaper style, which encodes component values in a page form into a format string with param1=value1&param2=value2 key-value pairs. It holds data for multiple request parameters. Not only can the message format pass the request parameters, but the request URL can also be passed via something like “/chapter15/user.html? Param1 =value1& Param2 =value2 is used to pass the request parameters.

HTTP Response

The HTTP response also consists of three parts, including a status line, a message header, and a response message.

The first part: the status line consists of HTTP/1.1 (protocol version) 200 (status code) OK (description of status code)

The second part: the response header, which specifies some additional information to be used by the client

Part three: The response body, where the server returns you the text message from the client

HTTP response status code

The status code consists of three digits. The first digit defines the category of the response and has five possible values:

  • 1×× : indicates that the request has been accepted. Continue processing
  • 2 x x: success – The request is successfully accepted, understood, or accepted
  • 3×× : Redirection – Further action must be taken to complete the vehicle request
  • 4 x x: client error – The request has syntax errors or cannot be implemented
  • 5 x x: Server error – The server failed to implement a valid request

The following are some common status codes, status descriptions, and instructions:

  • 200: OK- The client request succeeded
  • 400: Bad Request- The client Request has syntax errors and cannot be understood by the server
  • 401: Unauthorized- The request is not authorized. This status code must be used with the WWW-Authenticate header field
  • 403: Forbidden – The server receives the request but refuses to provide the service
  • 404: Not Found – Requested resource does Not exist, eg: Entered an incorrect URL
  • 500: Internal Server Error – An unexpected Error occurs on the Server
  • 503: Server Unavailable – The Server is currently unable to process client requests. However, the Server may become normal after a period of time

How HTTP works, features, and request/response steps

The principle of

The HTTP protocol defines how a Web client requests a Web page from a Web server and how the server delivers the Web page to the client. The HTTP protocol uses a request/response model. The client sends a request message to the server. The request message contains the request method, URL, protocol version, request header, and request data. The server responds with a status line containing the protocol version, success or error code, server information, response headers, and response data.

The characteristics of
  1. Client/server mode is supported.
  2. Simple and fast: when a client requests services from the server, it only needs to send the request method and path. The commonly used request methods are GET, HEAD and POST. Each method specifies a different type of contact between the client and the server. Because HTTP protocol is simple, the HTTP server program size is small, so the communication speed is very fast.
  3. Flexibility: HTTP allows the transfer of any type of data object. The Type being transferred is marked by content-Type.
  4. Connectionless: The meaning of connectionless is to limit processing to one request per connection. The server disconnects from the customer after processing the request and receiving the reply from the customer. In this way, transmission time can be saved. The reason for doing this early on was to ask for fewer resources and pursue faster. Connection: keep-alive (Persistent and non-persistent connections: In real applications, the client often makes a series of requests, and the server responds to each request. For these requests | response, if every time after a single TCP connection to send, called a persistent connection. On the contrary, if the same TCP connection is sent each time, it is called a persistent connection.
  5. Stateless: HTTP is a stateless protocol. Stateless means that the protocol has no memory for transaction processing. The lack of state means that if the previous information is needed for subsequent processing, it must be retransmitted, which can result in an increase in the amount of data transferred per connection. On the other hand, the server responds faster when it doesn’t need the previous information
Request/response steps
  1. The client connects to the server
  2. Sending an HTTP request
  3. The server accepts the request and returns an HTTP response
  4. Releasing the TCP Connection
  5. The client browser parses HTML content

HTTP and HTTPS

Hypertext Transfer Protocol Secure (HTTPS) is a Transfer Protocol for Secure communication over computer networks. HTTPS communicates over HTTP, but encrypts data packets using Secure Socket Layer (SSL) or Transport Layer Security (TLS). HTTPS is developed to provide identity authentication for web servers and protect the privacy and integrity of exchanged data.

HTTPS works on TCP port 443 by default. Its workflow is generally as follows:

  1. TCP Three-way handshake
  2. The client authenticates the server digital certificate
  3. DH algorithm Negotiates the keys of symmetric encryption algorithm and hash algorithm
  4. The SSL encryption tunnel negotiation is complete
  5. The web page is transmitted in encrypted way, and encrypted with negotiated symmetric encryption algorithm and key to ensure the confidentiality of data. The hash algorithm is used to protect data integrity from tampering.
The difference between
  • HTTP data is transmitted in plaintext and is not encrypted, which is insecure. HTTPS (SSL+HTTP) data is encrypted, which is secure.
  • To use HTTPS, you need to apply for a Certificate from the Certificate Authority (CA). Generally, there are few free certificates and some fees are required. Certificate authorities such as Symantec, Comodo, GoDaddy and GlobalSign.
  • HTTP pages respond faster than HTTPS, mainly because HTTP uses THE TCP three-way handshake to establish a connection. The client and server need to exchange three packets, whereas HTTPS requires the three PACKETS of TCP and the nine packets of SSL handshake, so the total number of packets is 12.
  • HTTP and HTTPS use completely different connections and use different ports, the former 80 and the latter 443.
  • HTTPS is an HTTP protocol built on TOP of SSL/TLS, so HTTPS requires more server resources than HTTP.
Working principle and steps
  1. The client initiates an HTTPS request
  2. Server Configuration
  3. Send the certificate
  4. The client parses the certificate
  5. Transmitting encrypted information
  6. The server decrypts the information
  7. Transmit encrypted information
  8. The client decrypts the information

conclusion

The above is about HTTP some knowledge in detail, I hope to give you in the study of HTTP related knowledge to answer a little doubt.