What is the HTTP protocol
Protocol refers to the rules or rules that must be adhered to in communication between two computers in a computer communication network, and Hypertext Transfer Protocol (HTTP) is a communication protocol that allows Hypertext Markup Language (HTML) documents to be routed from a Web server to a client's browser
The appearance of history
There are three issues with the transport of the Web over a network:
- How the client knows where to find the data address---URI
- How the client gets the content after it knows the address---HTTP
- What form of content is being identified by the client---HTML
HTTP Request Components
- Request Line
- HTTP Header
- Content
1. Request Line
GET www.cnblogs.com http/1.1
The three parts are composed of:
- Request method (common with Get,post)
- Url
- HTTP version
2.HTTP Head
Three kinds
- Requests header (Request header)
- Normal header (general header)
- Entity header Typically, because a GET request does not always contain a content entity, there is no entity header.
3. Content
The third part exists only in the POST request because the GET request does not contain any entities.
HTTP Response Components
- Status line
- HTTP Header
- return content
1. Status line
http/1.1 OK (HTTP status, status code)
Status Code classification
- Information Classes (100-199)
- Response Successful (200-299)
- Redirect (300-399)
- Client Error (400-499)
- Server-side error (500-599)
return content
HTTP response content is not only HTML, but also other types, then how the browser correctly docking received information to process? This is determined by the media type, which specifically corresponds to the Content-type HTTP header. The format of the media type is: Large class/small class. There are 8 kinds:
application-(for example: Application/vnd.ms-excel.)
Audio (for example: Audio/mpeg.)
Image (for example: Image/png.)
Message (for example,: Message/http.)
Model (for example: MODEL/VRML.)
Multipart (for example: Multipart/form-data.)
Text (for example: text/html.)
Video (for example: Video/quicktime.)
HTTP Header
Four categories
1. Header (HTTP request header)
A request header is a header that is sent by the client to the server to help the service side better satisfy the client request. The request header can only appear in the HTTP request.
- Accept:: Browser-side acceptable media types
- Cookies
- User-agent: Tells the HTTP server the name and version of the operating system and browser that the client is using.
- Range
- If-match-since: The last modification time of the browser-side cache page is sent to the server, and the server compares this time with the last modification time of the actual file on the server. If the time is the same, then return 304, the client uses the local cache file directly. If the time is inconsistent, 200 and the new file contents are returned. After the client receives it, it discards the old files, caches the new files, and displays them in the browser.
2. Response header (HTTP Response header)
The HTTP response header is the header that describes the HTTP response itself, which does not contain the header that describes the third part of the HTTP response, which is the HTTP message (this is partly the entity header)
- Refresh timed Refreshes
- Set-cookie: Used to send cookies to the client browser, each write cookie generates a Set-cookie.
3. Solid Head (Entity header)
is related to the content, so there is no post method and HTTP response in the request through the HTTP GET method.
- Content-type
- Content-length
- Content-language
- Conent-encoding
- Content-md5
- Expires: The browser will use the local cache within the specified expiration time; The last-modifies is used to indicate the last modification date and time of the resource.
4. Universal header (General header)
The HTTP itself can be described in the request/response.
- Connection:http whether persistent connections such as:
1.connection:keep-alive when a Web page opens, the TCP connection between the client and the server for transmitting HTTP data does not close, and if the client accesses the Web page on the server again, it will continue to use the established connection
2.connection:close represents the completion of a request, the TCP connection between the client and the server for transmitting HTTP data is turned off, and the TCP connection needs to be re-established when the client sends the request again.
- Date sent by date:http
- TCP connection time where the keep-alive:http is located
- Cache-control: whether to cache
HTTP features 1.http protocol is stateless
There is no correspondence between this request and the last request of the same client, and it is not known to the HTTP server that the two requests are from the same client. To solve this problem, the Web program introduces a cookie mechanism to maintain state.
2. Opening a Web page requires a browser to send many request
The server returns the data to the browser, and the browser interprets the data to find a lot of references such as CSS,JS. Then the request continues to be sent until all data has been downloaded
The 3.HTTP is TCP-based
HTTP is a transport-layer-based TCP protocol. So HTTP begins with a TCP connection before starting the transfer, and the TCP connection process requires a so-called "three handshake". After the TCP three handshake, a TCP connection is established, at which point the HTTP can be transmitted. An important concept is connection-oriented, where HTTP is not disconnected from the TCP connection between completion of the transfer.
- Http://www.cnblogs.com/CareySon/archive/2012/04/27/HTTP-Protocol.html
- Http://www.cnblogs.com/TankXiao/archive/2012/02/13/2342672.html
Learning from HTTP