HTTP protocol
7.1. What is the HTTP protocol:
The HTTP protocol is used to specify how the browser client and server communicate
7.2. Basic Principles
Request-based response model
One request corresponds to one response
Requests can only be made by the client, and the server can only passively wait for the request to respond
7.3.http protocol Detailed
7.3.1.Http Request
Request Line
Get/news3/1.html http/1.1
GET:
Submission method, a total of 7 (GET, POST, HEAD, OPTIONS, PUT, delete and Tarce), of which 5 are not used, only with GET and POST submission
/news3/1.html:
The path of the request resource
http/1.1:
The 1.0 and 1.1:1 versions of the protocol immediately disconnect the connection (channel) between the client and the server at the end of each communication, and if you need to send the request again, you can only establish a new connection
The 1.1 version of the protocol will keep the connection for a period of time after each communication, and if a request is sent during that time, the connection can be reused.
Several request headers
accept:text/html,image/*
--Notifies the server that the current browser can accept data in those formats
Accept-charset:iso-8859-1
--acceptable character set encoding for the browser
Accept-encoding:gzip,compress
--a compressed format acceptable to the browser
Accept-language:en-us,zh-cn
--The language environment that the browser accepts, and the internationalization-related head
Host:www.tedu.cn:80
--The name of the virtual host that needs to be accessed
!! Referer:
http://www.tedu.cn/index.jsp
--This is the header associated with the anti-theft chain, and the hyperlinks to which page the current resource is accessed from
user-agent:mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0)
--basic information of the client
!! Cookies
--the head associated with the cookie
Connection:close/keep-alive
--whether to keep the connection
Date:fri, 18:23:51 GMT
--The current time the request was sent
(A blank line)
Request Entity Content
Xxxxxx
7.3.2.Http response
A status line
http/1.1 OK
Version of the Http/1.1:http protocol
200: Status code, a three-bit number (100~600) indicates the server's results for request processing
Common Status Codes:
200: Indicates a successful processing request for the server
302: Request Redirection
304: Notifies the browser that the cache is being used
307: Notifies the browser that the cache is being used
404: Indicates that the resource cannot be found
500: There was an error inside the server!
OK: Description Information
Several response headers:
!! location:http://www.tedu.cn/index.jsp
--with 302 use to implement request redirection
Server:apache Tomcat
--Basic information of the server
Content-encoding:gzip
--compressed format used by the data sent by the server
Content-length:80
--the size of the data sent by the server
Content-language:zh-cn
--The server sends the data using the language environment internationalization-related header
!!! content-type:text/html; charset=gb2312
What is the format of the data sent by the server, and if it is character formatted data, you can also tell the server what encoding the data is sent from, and the browser will decide which encoding to use to open the received data based on the encoding specified by the header.
!! refresh:1;url=http://www.tedu.cn
--Refresh the relevant header periodically, notify the browser, and automatically refresh the access address after a few seconds
Content-disposition:attachment;filename=aaa.zip
--Notifies the browser to open the send past data as an attachment, which is the header associated with the file download
!!! SET-COOKIE:SS=Q0=5LB_NQ; Path=/search
--the head associated with the cookie
! Expires:-1
--Notifies the browser whether to cache
! Cache-control:no-cache
--Notifies the browser whether to cache
Pragma:no-cache
--Notifies the browser whether to cache
-The reason why a function has three heads is because of historical reasons. So for the sake of compatibility of web pages, usually these three headers are used together
Connection:close/keep-alive
--whether to stay connected
Date:fri, 18:24:11 GMT
--Time of response
(A blank line)
Responding to entity content
Xxxxxx
Basic knowledge of HTTP protocol