For the HTTP protocol also a beginner writer, writing this article, the main purpose is to facilitate their understanding of the content of the HTTP protocol, some not so professional and comprehensive description, please bear with me.
A, HTTP protocol overview
- HTTP protocol (HyperText Transfer Protocol, Hypertext Transfer Protocol) is the most widely used on the Internet A network transport protocol, all WWW documents must comply with this standard.
- HTTP is an application layer protocol, composed of a request and response, it is a standard client / server (C / S) model.
HTTP to communicate data based on TCP / IP communication protocol.
HTTP is a on the InternetTransfer ProtocolItself aC / S model,based onTCP/IPCommunication protocol to communicate data.
The so-called agreement is the mutual communication of agreed standards on human language and the same, only with the same protocol (language) of the two sides to communicate well.
Two, HTTP main features
- Based on a request / response model: Response time corresponding to the first request
The client is generallyterminal, The server is generallywebsite. By using a Web browser and other tools, the client initiates a HTTP request to the server to establish a designated port TCP connection. HTTP server that is sent over the port to listen for client requests. Upon receiving a request, the server (the client) and sends back a status line message.
- TCP / IP based high-level agreement
TCP / IP (Transmission Control Protocol / Internet Protocol, Transmission Control Protocol / Internet Protocol) refers to the protocol suite enables transmission of information between multiple different networks.
Here, the details of TCP / IP is not too much interpretation, knowing that a protocol (cluster) just fine.
- Stateless: requests each independent of each other, the data can not interact
No state is no protocol for transaction processing and memory. A disadvantage of this approach is that, if the subsequent processing is required before the information is used, it must be retransmitted, thus leading to each connecting transmission data amount is increased. Advantage is that, if subsequent information provided before the connection is not required, the response will be faster.
- no connection
No limitation is connected to each connection means to process only one request. After the server processes the client's request, then the response, and receiving the response, the connection is disconnected. This way it can save transmission time.
- The default port number: 80
Three, HTTP request
HTTP request format is:Request header request line + + + Request request lines blank body (body)
1. Request line
format:+ + Mode request URL request protocol request / release
-
Request method
most commonly used for theGETwithPOST。- GET
- When the client from the server to read the document, opening a link, or to browse the Web, use the GET method is through the browser enter the URL,
- GET method request and a corresponding parameter value is appended URL, using a? Representative of the end of the URL starts and accompanying parameters, parameters key = value pairs writing manner, separated by an ampersand between the parameters and parameter .
- Generally GET request parameter size is limited, the maximum does not exceed 1,024.
- Because the parameters are displayed in plain text URL above, and therefore is not suitable for transfer of private data.
Source: GET
- POST
- POST method request parameters encapsulated in the request body of the HTTP request in the form of name / value occurs, url length of the request is not limited.
- POST request is typically used to submit the form data.
- In contrast GET, POST safer
2. request header
Request header is the client browser to tell some special information server.
format:Request header name: request header value
Commonly used request header has
- User-Agent
browser tells the server, I access the browser version you are using information - Referer
represents jump to the page before the current page - Accept
response to the received content type - Origin
launched a shared resource for cross-domain request
3. Request blank line
Dividing the request header POST request, and the request body.
4. The request body
Package POST Request message parameter.
Four, HTTP response
format:In response to the first status line + + + Response body blank line
1. Status Line
format:Description protocol version HTTP status code + + status code
Common status codes have
- 404
server can not find the requested page - 403
access to the requested page is forbidden
Details can be found status code Gangster blog HTTP response status code reference .
2. Response Header
Constituted by a number of key-value pairs, to illustrate some additional information to be used by the client.
3. blank line
For dividing the response header and the response thereof.
4. Response Body
Specific information returned by the server to the client.
2019.12.15
References: