HTTP protocol
Summary: Hyper text Transfer Protocol (Hypertext Transfer Protocol) is an abbreviation for transferring hypertext to a local browser from the World Wide Web (www:world Wide Web) server.
The HTTP protocol belongs to the application layer, which transmits data based on TCP/IP protocol.
The HTTP protocol works on the client-server architecture, and the browser sends all requests to the HTTP server as an HTTP client through a URL, and the server then processes the request and returns the corresponding response information.
Three features of the HTTP protocol:
No connection: Restrict each connection to process only one request, when the server finishes processing the customer request and return the response, immediately disconnect (similar to short connection), so as to save the transmission time, http/1.0 default is short connection and http/1.1 after the default is long even packet header will have keepalive, Server-side need to turn on support.
Media independence: As long as the client and server side know how to handle the data content, any data type can be sent over HTTP, specifying the appropriate content type.
Stateless: There is no memory function for transaction processing, which means that the subsequent processing needs to be re-transmitted prior to the information, in order to maintain the session, we use a cookie and session to maintain the conversational mechanism.
Working principle:
HTTP long connection/short connection: In fact, the TCP/IP transport layer is a long connection and short connection;
Long connection: After both ends of the data transfer, the TCP connection is kept constant, waiting for the same domain name to be reused for the channel to transmit data.
Short connection: After the data transfer is complete, the TCP connection is disconnected directly, and the next time you need to establish a new connection to transfer data.
The pros and cons: long connections can bring higher TPS than short connections (processing messages per second, throughput), lower CPU consumption, less IO, higher memory footprint, fewer system calls
Long-connected usage scenarios and web_server-related configurations
Message structure
Client Request message Format:
Request Header (header)
Request Line
Blank Line
Request data
Server Response message Format:
Status line
Message header
Blank Line
Response body
Common methods
method |
description |
contains the topic |
GET |
Get a copy of a document from the server |
Whether |
POST |
Send data to the server that needs to be processed |
Is |
PUT |
Store the requested subject section on the server |
Is |
DELETE |
Delete a document from the server |
Whether |
How get and Post requests compare
Talk about the HTTP protocol