Network Basics - HTTP Protocol

Today, let's talk about the basis of our current network transmission, http (Hypertext Transfer Protocol). The following will introduce the URL, common methods, and package structure.

1. URL parsing

http:localhost:8081/ad
从这一条URL中我们可以知道的信息.
//http为使用的传输协议, 超文本传输协议允许传送html文件,
//localhost为主机地址,在我们访问其他网站的时候 会经过DNS服务器解析,变成相应的服务器IP 也就是主机地址.
//8081则为端口号,当前这个主机使用的端口号为多少, 实际上外部访问的时候 不会显示端口号.
//  /ad为服务器的访问路径, 通过这个路径可以访问到服务器上面的资源.

2. Common request methods and functions of http protocol

The most commonly used protocol is the http protocol, so we mainly explain the http protocol.

The common request methods of the Http protocol are as follows:

  • GET: The GET method is used to send a request to the server and obtain data, usually in the select query.

Features of the Get method

1. It is more convenient to use. After the URL address, use ? as the dividing line, and after the question mark is the data that the GET method wants to transmit.

2. The maximum length of the transmitted data is limited by the browser. Earlier, the length of IE was 1024 bytes, then the length of IE was 2048+35 bytes, and the length of firefox was unlimited. For compatibility with browsers, the unified use was 1024 bytes. bytes as the transfer limit.

3. The GET method has a faster transmission speed.

4. The GET method will not have any effect on the data, is safe, and is idempotent.

  • POST: The POST method is usually used for complex data transmission such as forms, and is also used to create resources in the parent directory when the exact URL of the child file is not known.

Features:
1. Theoretically, there is no limit to transfer data. It is determined according to the performance of the server. According to IIS6.0, the maximum limit is about 60M.

2. The transmission speed is slightly slower than the GET method

3. Non-idempotent, it may affect the data. Take creating data as an example, executing several POST requests may generate several pages, but PUT will not

  • DELETE: Usually used to delete data using

Features:
1. It is idempotent relative to the delete method, and the same is true for several operations.

  • PUT: Often used for updating, but also for resource creation.

1. The put method will update the resource when there is an exact URL. If the resource does not exist, it will be created, and if it exists, it will be updated.

2. Different from the POST method, the PUT method is idempotent. For the operation method, the result is the same when used several times. The page will only increase by one, and the updated data will not change.

3. The structure of the http package

Structure of HTTP packets

If we want to operate on the data packet sent by http, we need to know its structure.

The http package is divided into status line, header, blank line, and body.request and response.

Status line: It will be filled with the http protocol we use and what the version number is, and what method is used to make the request.

Header: HOST will indicate the destination of the request. User-Agent, which can be accessed by both server-side and client-side scripts, is an important basis for browser type detection logic.

body: The information we send in the request ps: The body of GET is empty, because the request is in the URL address.

4The actual role of http.

When the server and the client exchange data, we use the http protocol. Through the http protocol, the client can send data to the client and send a request in order to get the page they want or update the data.

The actual function is the data exchange between the client and the server.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325113146&siteId=291194637