5. Hypertext Transfer Protocol HTTP
5.1 Uniform Resource Locator URL
(1) General form of the URL:< protocol >://< host >:< port >/< path >
① agreement must be written on the following "://", can not be omitted;
② host refers to the host's domain name or IP address on the Internet;
③ ports and paths can sometimes be omitted.
(2) Example
①http URL general form:http://< host >:< port >/< path >. Where the port defaults to 80, it can usually be omitted.
②ftp URL general form: ftp://< host >:< port >/< path >. Where the port number defaults to 21. such as Ftp://user:[email protected]: 9921.
5.2 absolute path and relative path
(1) absolute Path (URL): Provides a full path to the file, including the protocols used, such as HTTP, FTP, and RTSP. such as http://www.sohu.com,ftp://202.136.254.1. absolute paths must be used when linking to other site resources .
(2) relative path : A file (or folder) that points to a folder within the site. As long as it is under the same site, even if it is not under the same directory, the relative path is also very appropriate.
① If you link to the same directory, you only need to enter the name of the document you want to link to.
② to link to a file in the next level of directory, simply enter the directory name, then add "/" and then enter the filename.
③ If you want to link to a file in the previous level of the directory, enter the first. /", then enter the directory name, file name.
(3) root path : Relative to the root directory of the Web site. Start with a slash, then the folder name, and the last file name. such as "/dir/file1.txt"
5.3 HTTP Protocol version
(1) Comparison of http1.0 and http1.1
① because of the large number of Web site visits, in order to improve the efficiency of the system,HTTP1.0 that the browser and the service only a short connection , each request of the browser needs to establish a TCP connection with the server . This also results in some performance flaws. For example, when a Web page file containing many images (such as a large number of tags), each download of an image file must create a separate TCP connection, it is afraid that the image file is too small. Due to the frequent establishment and shutdown of TCP connections, server performance can be severely impacted.
②http1.1 supports persistent connections . means that the Web server remains this connection for a period of time after the response is sent, so that the same client (browser) and the server's communication can continue to use the connection. This is not limited to sending documents linked on the same page, as long as the documents are on the same server, which reduces the waste of establishing and shutting down the connection. (IE is currently using http1.1 by default, can be set or canceled in tools → Internet Options → advanced → "HTTP1.1 settings" , if canceled, 1.0 version is used)
(2) http1.1 Continuous connection of two modes of operation
① features of the non-pipelined approach : The customer receives the previous response before making the next request. Therefore, after the TCP connection is established, the client will have to use a roundtrip time RTT for every object visited. If there are many files to download, the server's TCP connection handles idle state after sending an object, wasting server resources.
② Pipeline Mode Features: Customers receive HTTP response messages can then send a new request message. Then one after the request message arrives at the server, the server can connect sends back the response message . This way, the idle time of TCP connection is reduced, and the efficiency of downloading the document is improved. Therefore, the download speed is much faster than the non-pipelining.
5.4 HTTP Request messages and response messages
(1) request message (Request message sent from client to server)
① because http is text-oriented , each field in the message is a number of ASCII strings, usually ending with \ r \ n .
The ②http request message consists of three parts : A. start line . Mainly used for the difference between the request message or the response service. B. The first line , which is used to describe some information about the browser, server, or message body. The header can be multiple lines or not used. Each line ends with a "carriage return" and a "line break". The entire portion of the line ends with a "carriage return" and a "line break". C. entity Body . This field is generally not used in the request message and may not be in the response message.
There are 8 methods ( see ) in the "Request method" of the ③ "requesting line". Used to represent different ways to manipulate the resource specified by the Request URI, note that the method name is case -sensitive!
(2) Response message (reply from server to client)
The 1th line of the ① response message is the status line : Three items including HTTP version, status code, and a simple phrase explaining the status code.
② Status code ( status Code ) Total 5 major categories 33 kinds of
Status code |
Meaning |
1xx |
Represents a notification message. If a request is received or is being processed |
2xx |
Indicates success. If accepted or known. |
3xx |
Represents a redirect. Further action must be taken if the request is to be completed |
4xx |
Represents a client error. If the request has an incorrect syntax or cannot be completed |
5xx |
Indicates a server error. If the server fails to complete the request |
5.5 Cookies
(1) Introduction to Cookies:
① because HTTP is a stateless protocol . In order to log information, when a client requests a server, if the server record needs to log the user's state, a cookie is issued to the client browser using response, and the client browser saves the cookie.
② when the browser requests the site again, the browser submits the requested URL together with the cookie to the server . The server checks the cookie and optionally modifies the cookie's content.
(2)Export and import of cookies
① Export: Browse 126 mailboxes and select "Free login within 10 days". Then "file" → "Import and export" → "Export cookies" → Specify Where to save
② import: On another computer, open the browser → "file" → "Import and export" → "import cookie", then open 126 mailbox, the website automatically read the cookie and automatically log in.
(3) cookie security ( Delete cookie): "Internet Options" → "general" → "Delete Cookie"
5.6 Accessing a Web site through a proxy server
(1) Proxy Server application scenario
① uses a proxy server to bypass firewall blocking . Because the domestic firewall intercepts traffic to some foreign websites (such as B). However, there are many foreign Web proxy servers (such as C), domestic users can set the browser to use foreign proxy server, and then visit these sites can be successful.
② improve the access speed of intranet users . The proxy server can cache the content that the user has visited, and when another user accesses the same URL, the proxy server finds the information to be accessed from the cache and passes it to the user, thereby increasing the speed of access.
③ hides the real IP. Some Web site forums will record the IP address of the sender, you can use a proxy server to access, so that the site will only record the address of the agent, thus hiding their own IP.
(2) Erecting a Web proxy server
① the Win2003 virtual machine into a Web Proxy server : Run the Ccproxy software. (Note the native ip:192.16.80.20, after running the software by default on the 808 port listening to the client connection)
② usually the proxy server has two network cards, one connected to the Internet and one to the intranet. The network card connected to the intranet is the proxy address of intranet computer Internet. (The Web Proxy server in this experiment has a network card, so you need to specify which address can be used as the proxy address by ccproxy→ "account" → "Allow all" in "allowed Scopes").
(3) test agent
①on the XP machine specifies the use of a proxy server : Open ie→ tools → Internet options → connections tab → LAN settings → Enter IP and ports in the proxy server (as in the ip:192.168.80.20 above, port 808)
② Browse the site. Then, with Netstat-an , you can see only the TCP connection that was established with the Web proxy . You can also see this information in the "Monitoring" of WIN2003 's agent service software.
9th Application Layer (4) _ Hypertext Transfer Protocol HTTP