Http request and request
1. Basic request format
Basic Request formats includeRequest Line,Request Header,Request EntityThree parts. For example:
GET/img/bd_logo1.png HTTP/1.1
Accept :*/*
Referer: http://www.baidu.com/
Accept-Language: zh-cn
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1;. net clr 2.0.50727)
Host: www.baidu.com
Connection: Keep-Alive
Cookie: BAIDUID = B0DF0BDAD30649F69A8930D11BDB6DE8: FG = 1;
(Request Entity, but this is a GET request, so no Request Entity)
1. Request Line:
The method field, URL field, and HTTP Version field are recorded in the first line of the request. For example:
GET/img/bd_logo1.png HTTP/1.1
Above, GET is the request method,/img/bd_logo1.png is the request URL, and HTTP/1.1 is the request protocol and version.
2. Request Header:
Content located after the request line and before the independent empty line, for example:
Accept :*/*
Referer: http://www.baidu.com/
Accept-Language: zh-cn
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1;. net clr 2.0.50727)
Host: www.baidu.com
Connection: Keep-Alive
Cookie: a = 1
Request Header details:
Accept: the MIME type acceptable to the browser. */* indicates all types.
Referer: contains a URL from which you can access the current requested page.
Accept-Language: the type of Language that the browser wants to use when the server can provide more than one Language version.
Accept-Encoding: The data Encoding method that the browser can decode, such as gzip. Servlet can return gzip-encoded HTML pages to a browser that supports gzip. In many cases, this can reduce the download time by 5 to 10 times.
Accept-Charset: the acceptable character set of the browser.
User-Agent: browser type. This value is useful if the content returned by the Servlet is related to the browser type.
Host: Host and port in the initial URL. If the port is 80 by default, it is not displayed.
Connection: Indicates whether a persistent Connection is required. If the Servlet sees that the value here is "Keep-Alive", or the request uses HTTP 1.1 (HTTP 1.1 performs a persistent connection by default), it can take advantage of the advantages of persistent connections, when a page contains multiple elements (such as an Applet or image), the download time is significantly reduced. To achieve this, the Servlet needs to send a Content-Length header in the response. The simplest method is to write the Content into ByteArrayOutputStream first, then, calculate the size of the content before writing it.
Cookie: This is one of the most important request header information, which is usually placed at the end, because there may be a lot of content.
The above are the most common request headers, which are not seen below:
Authorization: Authorization information, usually displayed in the response to the WWW-Authenticate header sent by the server.
Content-Length: the Length of the Request Message Body.
From: the e-mail address of the Request sender, which is used by some special Web client programs and not used by the browser.
If-Modified-Since: the request is returned only when the requested content is Modified after the specified date. Otherwise, the system returns the 304 "Not Modified" response.
Pragma: specifying the "no-cache" value indicates that the server must return a refreshed document, even if it is a proxy server and has a local copy of the page.
UA-Pixels, UA-Color, UA-OS, UA-CPU: non-standard request headers sent by some versions of IE, indicating screen size, Color depth, operating system, and cputype.
3. Request Entity:
The request header and empty rows are request entities. Only requests in the POST method have request entities.