http: Communication Both parties must follow certain rules if they want to communicate, we call this rule the HTTP protocol!
Message: The content of the HTTP protocol communication we call: Message
Message Format: message header
Blank Line
Message body
1. Request message
Request Header: Request first line and request header
Blank Line
Request Body
2. Response message:
Response header
Blank Line
Response body
Message classification: Request message: Browser sent to server-side content
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
Request First line: Request request Resource "URL" request agreement/version number
Request Header: */* represents the type of document that the client can accept, */* indicates that any type can be accepted
Accept-language: Indicates that the current browser is located in the region, ZH-CN is the client's language in Simplified Chinese, en-us is the U.S. English!
Accept-encoding: When the browser sends a request to the server, it tells the server-side browser acceptable compression format!
Refer: Indicates which Web page the current page is jumping from. Host: Is the IP address and port number of the target host! Connection: Represents a communication connection between the browser and the server: Keep-alive means the session remains! The default session connection time is 3000ms! Cookie: is located on the browser side, and the server communicates use! Get request no blank line and request body!
POST Request 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:n O-cache cookie:jsessionid=774da38c1b78ae288610d77621590345 Username=admin
Request Header: Request first line: Request request URL Request Protocol/Protocol version number post/hello/target.html http/1.1 request header;
Blank Line
Request body: Content of the request
The difference between a GET request and a POST request: A 1.get request is a URL pass parameter, and a POST request is passed through the request body.
2.get requests are allowed to pass a maximum of 255 characters, there is a limit to the length, so the data is relatively large when we use the POST request, especially when uploading with a POST request!
3.get request we can see the request parameters in the browser, and the post request in the browser address bar is not see the request parameters!
Response message: The content response message sent to the browser by the server is the response header [response first line and response header], blank line, response body
http/1.1 OK
server:apache-coyote/1.1
Content-type:text/html;charset=utf-8
content-length:274
Date:tue, APR 10:08:26 GMT
<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" >
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">
<title>insert title here</title>
<body>
</body>
Response First line: Communication protocol/version number response status code
Response header:
Server: Apache
Response body Encoding type: Content-type
Response Body Length: content-length
Response Time: Date
Blank Line
Response Body!
Response Status Code: 200: Indicates a successful response
302: Redirect is indicated
404: Wrong URL for the request!
500: Server-side Error!
HTTP protocol introduction and GET and POST request, response status code