I. Introduction to the HTTP protocol
1, the client connected to the Web server, if you want to get a Web server in a Web resource, you need to follow a certain communication format, the HTTP protocol is used to define the client and Web server communication format. In a DOS environment, a Web server can be connected directly via the telnet command. Use the HTTP protocol to send a request for a page.
2, HTTP is a Hypertext Transfer Protocol, it is a TCP/IP protocol Application layer protocol, used to define the Web browser and Web server Exchange data between the process, the HTTP protocol is learning Javaweb development of the cornerstone, do not understand the HTTP protocol, can not say that mastered the web development, More difficult to manage and maintain some complex web sites.
3, the version of the HTTP protocol has http/1.0, http/1.1, in the HTTP1.0 protocol, the client and the Web server after establishing a connection, can only obtain a Web resource, HTTP1.1 protocol, allowing the client to establish a connection with the Web server, Get multiple Web resources on a single connection. You can use Telnet authentication, which is now using http1.1.
4, a Web page, using the IMG tag refers to three pictures, when the client accesses this Web page in the server, the client will access a total of several servers, that is, the server sent several HTTP requests. One of the following pages:
"Text/javascript"Src="..."/><link rel="stylesheet"Type="Text/css"href="Css/reset.css">"a"Src="A.png"> "b"Src="B.png"/></body>
When a client accesses this page, it will send a total of 5 requests to the server, because the browser can parse these js,css, pictures and other resources, resolve to the corresponding resources on the server, then will send the request to the server. So talk about these things merge, reduce the number of server visits, Can alleviate the pressure of the server to some extent. When you visit Sina's homepage, hundreds of requests are sent to the server.
Second, HTTP request
1. After the client connects to the server, it requests a Web resource from the server, which is called the client sends an HTTP request to the server. A complete HTTP request includes the following: A request line, a number of message headers, and the entity content, a blank line between the request header and the body content, as follows:
2. Details of HTTP request-- request Line
The get in the request line is called the request method, the request method currently mainly has get, POST, the user is not set, by default, the browser sends to the server is a GET request, for example, in the browser direct output address access, point hyperlink access, etc. are get, the user wants to change the request mode to POST, You can change the way forms are submitted or AJAX implementations. Regardless of whether post or get is used to request a Web resource to the server, the difference between the two approaches is mainly in the data delivery: If the request is a Get mode, you can bring the data to the server in the form of the requested URL. Multiple data is separated by &, for example: get/mail/1.html?name=abc&password=xyz http/1.1,get: The parameters that accompany the URL address are limited, Its data capacity is usually not more than 1K. If the request is in the form of post, you can send data to the server in the requested entity content, the Post method features: The amount of data transmitted is unrestricted.
3. Details of HTTP request-- message header
Cases:
The main message header has the following meanings:
Ps:1.accept */* representative can accept any data. 2.if-modified-since, the server receives this time and will be compared with the last time to access the resource, if the resource is greater than the last time to take the client's buffer and not to access the server, Returns a status code of 304 or 307, and returns a status code of 200 if it is less than the resource's new time to access the Web resource.
Second, HTTP response
1. An HTTP response represents the data that the server sends back to the client, including: A status line, several message headers, and entity content.
Cases:
2. HTTP response Details-- status line
Format: HTTP version number status code reason description <crlf>, for example: http/1.1 OK, the status code is used to indicate the server's processing result for the request, which is a three-bit decimal number. The response status code is divided into 5 classes, as follows:
ps:100-199 is rarely used, 307 and 304 indicate that the requested resource is taken from the buffer, 404 means that the Web resource being accessed does not exist, must be a client problem, and 403 means that there is no permission to access the resource.
3, HTTP response details-- Common response header
The server can take full control of browser behavior through the response header, for example:
The meaning is as follows:
HTTP Utility Header Field-range implement the breakpoint continuation function, slightly.
You can write a servlet program, set the response header, to see the behavior of the browser specifically.
Java EE (2) _http protocol