I. Common header fields
1. Connection
This field only exists in http1.1 protocol. It determines whether the server immediately closes the network connection after a session is held between the client and the server. The most direct result on the client is to use the read method (the same is true for the Readline method) to check whether-1 is returned immediately after reading the Web Resources requested by the client (null is returned for Readline ). Connection has two values: close and keep-alive. When connection: Close is used, it is the same as http1.0 protocol. When the read method reads data and the connection: keep-alive method is used, the read method is blocked for a period of time after reading data. After the time-out period for direct data reading, continue to execute. As discussed in the previous articleReadhttpresponse (...)The 011st rows implemented by the method can verify the function of connection. Next, let's use the HTTP Simulator for an experiment.
(1) enter the following domain name in the HTTP simulator:
Www.baidu.com
(2) enter the following HTTP request information in the HTTP simulator:
Get, HTTP, 1.1
HOST: www.baidu.com
(3) Press ENTER twice (enter an empty line), send the request message, and get the HTTP Response Message Header shown in 1:
Figure 1
(4) Enter y or Y to display the content of the response message. (enter y or y immediately after the HTTP response header is displayed. After the content is displayed, it takes about 10 seconds to enter the "host: Port>" prompt (becauseSendhttprequest ()(Row 004 in the Implementation Code sets the data read timeout ).
(5) Press enter at the "host: Port>" prompt and enter the last domain name www.baidu.com and port 80. Enter the following HTTP request again:
Get, HTTP, 1.1
HOST: www.baidu.com
Connection: Close
After entering the preceding HTTP request, re-Execute steps 3rd and 4. After the HTTP Response Message is displayed, the "host: Port>" prompt is directly entered. In addition to this method, change the first line of the request to get/HTTP/1.0. In this way, you do not need to wait for the end.
By setting connection, you can immediately disconnect the network after downloading web resources (such as multi-thread download tools and Web browsers), which can effectively reduce the client resource consumption.
2. Date
This date header field describes the time when the request message and Response Message were created. The value of this field is of the HTTP-date type. The format must be GMT (Greenwich Mean Time), and GMT is Beijing time minus 8 hours. The following is an example of the date field:
Date: Tue, 15 Nov 2007 08:12:31 GMT
3. Content-Length
Specifies the number of bytes of the message entity. In the request message, the POST method must use Content-Length to specify the number of bytes of the object content of the request message. In the response message, this field value specifies the number of bytes of the Web Resource returned by the current HTTP response.
Ii. http request message header field
1. Host
The Host field is used to specify the host name and port number of the resource accessed by the client. If the port number is equal to the port number used to connect to the server, the port number can be omitted. The following is an example of using the host field:
HOST: www.sina.com.cn
This field is required. If an HTTP request does not contain this field, the server returns the 400 (Bad request) response status.
2. Accept
The accept field header determines the media type that the client can receive. The general format is "*/*" or "type/" subtype ". This sub-field header can pass multiple media types separated by commas. The following is an example of accept:
Accept: image/GIF, image/jpg
If the request header uses the above accept field value, the server will first contain GIF images when dynamically generating the IMG header of the webpage. If the GIF image does not exist, it contains JPG images.
3. User-Agent
This field header is used to specify the server accessed by the client. If it is an IE6 browser and. NET 2.0 is installed on the local machine, the User-Agent will have the following values:
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; sv1; Maxthon;. Net CLR 1.1.4322;. Net CLR 2.0.50727; infopath.1; infopath.2)
The server can use this field to check the client's browser version and determine the data sent to the client based on different versions.
4. Range
The range field header transmits only some web resources through the server. This field header can be used to implement the resumable upload function. Many download tools use this field header for resumable data transfer. The range field can be used to set the byte range to be transmitted in three formats:
(1) range: bytes = 1000-2000
The transmission range is from 1000 to 2000 bytes.
(2) range: bytes = 1000-
Transmits all content after 1,000th bytes in a web resource.
(3) range bytes = 1000
Transmit the last 1000 bytes.
3. Http response message header field
1. Accept-ranges
This field indicates whether the Web server supports range (whether resumable data transfer is supported). If yes, the system returns accept-ranges: bytes. If not, the system returns accept-ranges:
None.
2. Content-Range
Specifies the byte range of the returned web resource. The format of this field value is:
Start byte location-end byte location/total number of bytes of web resources
The following is an example of using content-range:
Content-range: 1000-3000/5000
Test
Connect to the server files.cnblogs.com in the HTTP simulator and enter the following HTTP Request Message:
GET/nokiaguy/httpsimulator.rar HTTP/1.1
HOST: files.cnblogs.com
Value Range: bytes = 1000-
The returned Response Message Header 2 is shown below:
Figure 2
We can see that the files.cnblogs.com server supports resumable data transfer. It can also be verified that the value of Content-Length is the number of bytes passed by the current session, not the total number of bytes of web resources. The number following "/" in the Content-range field value is the total number of bytes of web resources.
3. Location
This field specifies the new address on which to obtain the new web resource. After the web resource is changed, some old users cannot know the new URL in time. Therefore, when the old user accesses the original URL, the new URL is returned to the client using location. This address translation is completely transparent to users.
Go to: http://www.blogjava.net/nokiaguy/archive/2009/nokiaguy/archive/2009/08/archive/2009/nokiaguy/archive/2009/nokiaguy/archive/2009/07/archive/2009/06/23/283723.html