This is the 14th day of my participation in Gwen Challenge
The HTTP protocol
Defining HTTP, HyperText Transfer Protocol (HyperText Transfer Protocol) is the most widely used network Protocol on the Internet. All WWW files must comply with this standard. HTTP was originally designed to provide a way to publish and receive HTML pages.
The Http protocol consists of Http request and Http response. When you enter a url to visit a website, the browser encapsulates your request as an Http request and sends it to the server. After receiving the request, the server encapsulates the response data as an Http response and sends it back to the browser: No request, no response.
The HTTP request
Edit a form page in form.html as follows:
Click the submit button to capture the packet as follows:
1) Request line
Request mode: POST and GET
Requested resource: /DemoEE/form.html
Protocol version: HTTP/1.1
HTTP/1.0, send a request, create a connection, get a Web resource, and disconnect.
HTTP/1.1, send a request, create a connection, get multiple Web resources, maintain the connection.
2) Request headers
The request header is some information that the client sends to the server, using key-value pairs to represent key: value
Common request headers | Description (bold grasp, other understanding) |
---|---|
Referer | The browser informs the server where the current request is coming from. If you are accessing directly, you will not have this header. Often used for: anti-theft chain |
If-Modified-Since | The browser notifies the server of the last change in the local cache. The combination with another response header controls the caching of the browser page. |
Cookie | Session-related technology used to store cookie information cached by the browser. |
User-Agent | The browser notifies the server, the client browser, and the operating system |
Connection | Keep the connection state. Close is closed in the keep-alive connection. Procedure |
Host | The host name of the requested server |
Content-Length | The length of the request body |
Content-Type | If it is a POST request, it will have this header, which defaults to Application/X-www-form-urlencoded, indicating that the request body content is URL-encoded |
Accept: | MIME types supported by browsers. A description of a file type. MIME format: large type/small type [; parameter] for example: text/ HTML, HTML file text/ CSS, CSS file text/javascript, JS file image/*, all image files |
Accept-Encoding | The browser notifies the server of the data compression format supported by the browser. For example, GZIP compression |
Accept-Language | The browser notifies the server of the language the browser supports. National Languages (Internationalization I18N) |
3) Request body
When the request is POST, the requestor has the following parameters:
username=zhangsan&password=123
If the request type is GET, the request parameters do not appear in the request body and are concatenated after the URL address
http://localhost:8080… ? username=zhangsan&password=123
The Http response
1) Response line
The Http protocol
Status code:
Common status codes are as follows:
200: Request succeeded.
302: Request redirection.
304: The requested resource has not changed, accessing the local cache.
404: Requested resource does not exist. Typically, the user path was written incorrectly, or perhaps the server resource was deleted.
500: The server has an internal error. Usually the program throws an exception.
Status information: The status information changes according to the status code
2) Response header
The response is also in the form of key-value pairs, and the server sends information back to the client as key-value pairs
Common request headers | describe |
---|---|
Location | The response path must be used together with the status code 302 to complete the jump. |
Content-Type | The response body type (MIME type) can be text or HTML. charset=UTF-8 |
Content-Disposition | Parsing text in download mode through a browser Values: attachment; filename=xx.zip |
Set-Cookie | Session-related technologies. The server writes cookies to the browser |
Content-Encoding | Compression format used by the server Value: gzip |
Content-length | The length of the response body |
Refresh | Periodic refresh, format: seconds; Url = path. The URL can be omitted; the default value is the current page. Value: 3; url=www.itcast.cn// Refresh the page to www.itcast.cn in three seconds |
Server | This is the server name. Default: apache-coyote /1.1. This can be modified through the conf/server.xml configuration. The < Connector port = “8080”… Server = “itcast” / > |
Last-Modified | The server notifies the browser when the file was last modified. Used with if-modified-since. |
3) Response body
The response body is the body of the page that the server writes back to the client. The browser loads the body into memory and then parses and renders the page content
That’s all for today’s content. If you have different opinions or better ideas, please contact Ah Q: Qingqing-4132. Ah Q can invite you to join the technical group to discuss technology together. Ah Q is looking forward to your arrival!