The HTTP request is initiated by the client and refers to the request message from the client to the server.
How to initiate an HTTP request
With the help of HTTP tools and knowing the URL, this HTTP request can be initiated.
Enter a URL in the browser address bar and press enter to initiate the HTTP request.
The URL (uniform resource locator / Web address) format is:
Protocol: / / server IP address (: port) / path / (? Query) / / the default port can be omitted, and the query part may notNote:
1. IP address is the logical address used to uniquely identify the computer on the Internet. Each networked computer depends on IP address to distinguish and contact each other. However, IP address is a digital identification, which is difficult to remember and write. Therefore, based on IP address, a symbolic address scheme is developed to replace digital IP address. Each symbolic address corresponds to a specific IP address. This character type address corresponding to the digital IP address on the network is called the domain name. Multiple domain names can resolve one IP at the same time, but one domain name cannot resolve multiple IPS.
2. The port can be omitted. When omitted, the default port is used. The default port number is 80 for HTTP protocol and 443 for HTTPS protocol.
https :// www.baidu.com /baidu ?tn=monline_7_dg&ie=utf-8&wd=1
Protocol: / / server IP address（Domain name) / path? query
https :// www.w3school.com.cn /html/html_jianjie.asp
Protocol: / / server IP address（Domain name) / path (file path with hierarchy)/
In Linux system, HTTP request can be initiated with curl command, and in Windows system, curl.com can be used Exe tool (you need to download it yourself).
HTTP request format
HTTP request consists of three parts: request line, request header and request body. (it can be viewed by pressing F12 in the browser)
POST /page/index/checkCode.php HTTP/1.1
User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:94.0) Gecko/20100101 Firefox/94.0
Accept-Encoding: gzip, deflate
The first line is the request line;
The composition method is: request method (post) / address requested under the root directory of the domain name (/ page / index / checkcode. PHP) / protocol and version used (HTTP version 1.1)
The second line to the blank line are the request header, which is the additional information transmitted by the client to the server, or the information of the client itself.
The last line is the request body. (most often in post requests, get requests have no request body)
HTTP request method
The get method is used to obtain the specified information of the request page and return the entity body. When we open and browse an ordinary web page, we usually make a get request. For example, click to open this blog now（
Similar to get, the difference is that the post request has a request body, which is used to transmit a large amount of data to the server, and the information will not be displayed in the URL. It is safer than get. Used for uploading files, login, registration, etc.
Note: the difference between get request and post request
Except that it does not return the message body, it is the same as get. It is used to obtain the message header (echo header). It can verify the effectiveness of a resource (you can understand the content stored in the response header). Because it does not return the message subject (response body), it is very fast.
The entity part in the request can be saved under the requested resource. If the requested resource already exists in the server, the original requested resource will be replaced with the entity part in the request. Use to create a new resource or replace a specified resource.
Used to request the deletion of the specified resource requested by the server.
The request received by the server can be echoed, so that the user can understand the reception of the party whose data is requested, and can be used for diagnosis and debugging.
This method is used for proxy servers that can change the connection to pipeline mode.
It is used to request to obtain the function options that can be used in the communication process of the requested resource, or to view the performance of the server.
It is only used in HTTP requests. It enables the client to pass the client’s own information and additional information to the server.