The HTTP protocol stands for Hyper Text Transfer Protocol, which is used to transfer hypertext from World Wide Web (WWW) servers to local browsers. It operates based on TCP/IP communication, thus functioning on a client-server model. It is an application layer protocol that can be used to transfer various resources from the server, such as text, images, audio, etc.URL and ResourcesURL stands for Uniform Resource Identifier, which is the absolute address used on the Internet to identify a specific resource. Using it, we can find the resource unless it has been moved.URL Components:
| Component | Description |
|---|---|
| Scheme | Specifies which protocol to use when accessing the server for resources, including HTTP, HTTPS, FTP, SMTP, etc. |
| User | Some schemes require a username to access resources for authorization. |
| Password | A password may be needed for verification after the username, separated by a colon “:”. |
| Host | The hostname or IP address (in dot-decimal notation) of the resource’s host server. |
| Port | The port number that the resource host server is listening on. Many schemes have default port numbers, so we don’t need to fill them in ourselves. For example, HTTP uses port 80 by default, and HTTPS uses port 443. The port is not a mandatory part of a URL; if omitted, the default port is used. |
| Path | The path to the local resource on the server, similar to a file path on a computer, separated from the port by “/”. It starts from the first “/” after the domain name to the last “/”. The virtual directory is also not a mandatory part of a URL, and after the path, a filename is required, which is the resource specified by the URL. The filename part is also not mandatory; if omitted, the default filename is used. |
| Params | Some schemes use this component to input parameters, which can have multiple parameters separated from the path by a “;” symbol. |
| Query | Some schemes use this component to pass parameters to activate applications, with no universal format for the query component, separated from other components by a “?” character. |
| Fragment | A small piece or part of a resource’s name. When referencing objects, the fragment component’s content is not transmitted to the server; this field is used internally on the client side, separated from other components by a “#” character. |
HTTP MessageThe HTTP message consists of three parts: the “start line” that describes the message, the “headers” that contain attributes, and the optional “entity body”. The request message and response message differ only in the format of the “start line”.HTTP Request Message
<method> <request-URL> <version> // Start line <headers> // Headers
<entity-body> // Entity body
HTTP Response Message
<version> <status> <reason-phrase> // Start line <headers> // Headers
<entity-body> // Entity body
Contents of Each Part of the HTTP Message:
- Method: The start line of the HTTP request message begins with the method, which informs the server what to do. Common methods include GET, POST, HEAD, etc. For example, “GET /forum.php HTTP/1.1” uses the GET method.
- Request URL: Specifies the requested resource.
- Version: Specifies the HTTP protocol version used in the message, where <major> specifies the major version number, and <minor> specifies the minor version number.
- Status Code: This is used in the HTTP response message. The status code is a numeric code returned in the start line of each response message that describes the status of the request process, such as success or failure. Different status codes have different meanings.
Overall Range Defined Usage Range Description 100 ~ 199 100 ~ 101 Informational 200 ~ 299 200 ~ 206 Success 300 ~ 399 300 ~ 305 Redirection 400 ~ 499 400 ~ 415 Client Error 500 ~ 599 500 ~ 505 Server Error
- Reason Phrase: This is essentially a reason phrase for us, as the numbers are not intuitive; it is merely a textual representation of the status code.
- Header: An HTTP message can have 0, 1, or multiple headers. HTTP header fields add some additional information to the request and response messages. Essentially, they are a name:value pair, with each header containing a name followed by a colon “:”, an optional space, and then a value, ending with CRLF. For example, “Host: www.baidu.com” is a header.
- Entity Body: This part contains a block of data composed of any data. It is actually the same as the message data area we discussed earlier, used to carry data. HTTP messages can carry many types of digital data: images, videos, audio, HTML documents, software applications, etc.