HTTP protocol,
1. HTTP Protocol Introduction
L HTTP (hypertext transport protocol), that is, hypertext Transfer protocol. This protocol details the rules for communication between browsers and web servers.
L The content transmitted when the client communicates with the server is called a message.
LHTTPIt is a communication rule.Specifies the format of the message sent from the client to the server.The format of the message sent from the server to the client. What we need to learn is the two types of packets. What the client sends to the server is called"Request Message", What the server sends to the client is called"Response Message".
2. Install HttpWatch2.1
L because IE8 and lower ie browsers do not provide HTTP listening functions, you must install HttpWatch as a tool to view HTTP request content in IE8 and lower browsers.
L both Firefox and chrome have built-in Developer Tools to directly view Http requests.
L HttpWatch is easy to use. Install HttpWatch directly and continue until the installation is complete.
2.2 Use
L after the installation is complete, open ie. the HttpWatch Professional option is displayed in the tool drop-down list.
L click Record to start listening to Http requests.
3. 3.1 packet format
3.2 request message 3.1.1 Message format
The first line of the request; Request Header information; Empty rows; Request body; |
3.1.2 GET request
GET/Hello/index. jsp HTTP/1.1 Accept :*/* Accept-Language: zh-CN User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2 ;. net clr 2.0.50727 ;. net clr 3.5.30729 ;. net clr 3.0.30729; Media Center PC 6.0 ;. NET4.0C ;. NET4.0E) Accept-Encoding: gzip, deflate Host: localhost: 8080 Connection: Keep-Alive Cookie: JSESSIONID = C55836CDA892D9124C03CF8FE8311B15 |
GetThe request has no request body, so there is no blank line!
L GET/Hello/index. jsp HTTP/1.1: GET request. The request server path is Hello/index. jsp, and the protocol is 1.1;
L Host: localhost: the requested Host name is localhost;
L User-Agent: Mozilla/4.0 (compatible; MSIE 8.0... : Information related to browsers and OS. Some websites will display the User's system version and browser version information, which is obtained by obtaining the User-Agent header information;
L Accept: */*: indicates the type of documents that the current client can receive. */* indicates that all documents can be received;
L Accept-Language: zh-CN: Language supported by the current client. You can find the Language information in the tool option of the browser;
L Accept-Encoding: gzip, deflate: supported compression formats. When data is transmitted over the network, the server may compress the data before sending it;
L Connection: keep-alive: the Connection method supported by the client. The default value is 3000 ms;
L Cookie: JSESSIONID = 2017766fdf6220f7803433c0b2de36d98: because it is not the first time to access this address, the Cookie sent from the last server response is sent in the request and sent in the request.
3.1.3POST request
L The POST request requires that the method attribute of the form label be set to post
POST/Hello/target.html http/ 1.1 Accept: application/x-ms-application, image/jpeg, application/xaml + xml, image/gif, image/pjpeg, application/x-ms-xbap ,*/* Referer: http: // localhost: 8080/Hello/ Accept-Language: zh-CN User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2 ;. net clr 2.0.50727 ;. net clr 3.5.30729 ;. net clr 3.0.30729; Media Center PC 6.0 ;. NET4.0C ;. NET4.0E) Content-Type: application/x-www-form-urlencoded Accept-Encoding: gzip, deflate Host: localhost: 8080 Content-Length: 14 Connection: Keep-Alive Cache-Control: no-cache Cookie: JSESSIONID = 774DA38C1B78AE288610D77621590345 Username = admin |
L POST requests can be specific, while GET requests cannot.
L Referer: http: // localhost: 8080/hello/index. jsp: Request from which page, for example you click here on Baidu link, then Referer: http://www.baidu.com; if you are in the browser address bar directly input the address, then there is no Referer request header;
L Content-Type: application/x-www-form-urlencoded: indicates the Data Type of the form. The url format is used to encode the data. The url-encoded data is prefixed with "%, followed by two hexadecimal values, for example, Neusoft uses the UTF-8 url encoded as "% E4 % BC % A0 % E6 % 99% BA ";
L Content-Length: 13: Length of the Request body, which is 13 bytes.
L keyword = hello: Request body content! Hello is the data input in the form, and keyword is the name of the form field.
3.3 Response Message 3.2.1 Message format
Response to the first line; Response Header information; Empty rows; Response body; |
HTTP/1.1 200 OK Server: Apache-Coyote/1.1 Content-Type: text/html; charset = UTF-8 Content-Length: 274 Date: Tue, 07 Apr 2015 10:08:26 GMT <! DOCTYPE html PUBLIC "-// W3C // dtd html 4.01 Transitional // EN"> <Html> <Head> <Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"> <Title> Insert title here </title> </Head> <Body> <H1> Hello </Body> </Html> |
L HTTP/1.1 200 OK: The response protocol is HTTP1.1 and the status code is 200, indicating that the request is successful;
L Server: Apache-Coyote/1.1: Server version information;
L Content-Type: text/html; charset = UTF-8: The response body is encoded as a UTF-8;
L Content-Length: 274: The response body is 274 bytes;
L Date: Tue, 07 Apr 2015 10:08:26 GMT: response time, which may have an eight-hour time zone difference;
L
3.2.2 response code
The response code is very important to the browser. It tells the browser the response result;
L 200: when the request is successful, the browser displays the response body (usually html) in the browser;
L 404: the requested resource is not found, indicating that the client has mistakenly requested a nonexistent resource;
L 500: the requested resource is found, but an error occurs in the server;
L 302: redirection. When the response code is 302, it indicates that the server requires the browser to re-send a request, and the server will send a response header Location, which specifies the URL address of the new request;