Home > Article > Web Front-end > http protocol request_html/css_WEB-ITnose
The basic format of request includes request 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;
(requesting entity, but this is a GET request so there is no requesting entity)
is located in the first line of the request and records the method field, URL field, and HTTP version field. For example:
GET /img/bd_logo1.png HTTP/1.1
Above, GET is the request method, /img/bd_logo1.png is the request URL, HTTP/1.1 is the request protocol and version.
The 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: MIME acceptable by the browser Type, */* indicates all types.
Referer: Contains a URL from which the user accesses the currently requested page.
Accept-Language: The language type desired by the browser, used when the server can provide more than one language version.
Accept-Encoding: The data encoding method that the browser can decode, such as gzip. Servlets can return gzip-encoded HTML pages to browsers that support gzip. In many cases this can reduce download times by 5 to 10 times.
Accept-Charset: The character set acceptable to the browser.
User-Agent: Browser type, this value is very useful if the content returned by the Servlet is related to the browser type.
Host: The host and port in the initial URL. If the port is the default 80, it will not be displayed.
Connection: Indicates whether a persistent connection is required. If the servlet sees the value here as "Keep-Alive", or sees that the request is using HTTP 1.1 (HTTP 1.1 makes persistent connections by default), it can take advantage of persistent connections when the page contains multiple elements (e.g. Applet, picture), significantly reducing the time required for downloading. To achieve this, the Servlet needs to send a Content-Length header in the response. The simplest way to achieve this is to first write the content to a ByteArrayOutputStream, and then calculate its size before officially writing the content out.
Cookie: This is one of the most important request header information and is usually placed at the end because there may be a lot of content.
The above are the most common request headers, the following ones are rarely seen:
Authorization: Authorization information, usually appears in the response to the WWW-Authenticate header sent by the server.
Content-Length: Indicates the length of the request message body.
From: The email address of the request sender. It is used by some special web client programs and will not be used by the browser.
If-Modified-Since: Return the requested content only if it has been modified after the specified date, otherwise return a 304 "Not Modified" response.
Pragma: Specifying a "no-cache" value means that the server must return a refreshed document, even if it is a proxy server and already has a local copy of the page.
UA-Pixels, UA-Color, UA-OS, UA-CPU: Non-standard request headers sent by certain versions of IE browsers, indicating screen size, color depth, operating system and CPU type.
After the request header and the blank line, there is the request entity. Only requests with the POST method have request entities.