http protocol
HTTP Overview
HTTP is the abbreviation of Hypertext Transfer Protocol, and its Chinese name is “Hypertext Transfer Protocol.” It specifies the format and interaction rules for requests and responses between clients and servers.
HTTP usually runs on top of TCP. The client first sends an HTTP request to the server, and the server returns an HTTP response after processing it.
The main characteristics of HTTP
stateless
The HTTP protocol itself does not automatically remember the business status from previous requests. The server can maintain login status and business data through mechanisms such as cookies, Session, Token or database.
Request and response models
An HTTP interaction usually consists of a request and a response. HTTP/1.1 supports persistent connections by default, so it cannot be simply understood as “the TCP connection must be disconnected immediately after each request ends.” Whether a connection is reused also depends on the protocol version, request headers, server configuration, and network environment.
http request message
An HTTP request message usually consists of the following parts:
-
Request line.
-
Request header.
-
Blank line.
-
Optional request body.
request line
The request line contains the request method, request target, and HTTP version, for example:
GET /users?id=10 HTTP/1.1
The query parameters are located in the request target and are not part of the request header.
Common request methods
GET
Usually used to obtain resources. Query parameters are often written after the URL, so they easily appear in the address bar, browser history, server log, etc.
GET is not naturally more “insecure” than POST; whether it is safe depends on factors such as whether HTTPS is used, whether sensitive parameters are exposed, and server permissions verification. There is also no fixed upper limit for URL length that is uniformly stipulated by HTTP, but browsers, servers, and proxies may set their own limits.
POST
It is usually used to submit data to the server or trigger processing operations. When using method="post" for forms, form data is usually placed in the request body.
HEAD
Similar to GET, but the server only returns the response header and does not return the response body. It is often used to obtain resource metadata.
PUT
It is usually used to create or replace specified resources as a whole, and is more common in REST-style interfaces.
DELETE
Usually used to delete specified resources. The server still needs to undergo identity authentication, authority check and business verification.
Common request headers
| request head | action |
|---|---|
Accept | declares the type of response content that the client can receive |
Accept-Language | declares the client’s preferred language |
Content-Type | declares the data type of the request body |
Cookie | sends qualified cookies to the server |
Common request body types
Form coding
Content-Type: application/x-www-form-urlencoded
Example of request body:
username=tom&password=123
file upload
Content-Type: multipart/form-data
This format can submit ordinary fields and file content in the same request, and the actual request header will also contain boundary used to separate various parts.
XML
Content-Type: application/xml
JSON
Content-Type: application/json
JSON uses double quotes to represent the object’s property names and string values:
{
"username": "tom",
"password": "123",
"name": "tom"
}
{
"name": "财务部",
"id": 5001,
"employees": [
{
"name": "tom",
"age": 20
},
{
"name": "jack",
"age": 23
}
]
}HTTP response message
An HTTP response message usually consists of the following parts:
-
Status line.
-
Response head.
-
Blank line.
-
Optional response body.
Example status line:
HTTP/1.1 200 OK
HTTP status code
The status code consists of three digits, with the first digit indicating the response category.
| Status Code | Name | Meaning |
|---|---|---|
200 | OK | request was successful |
400 | Bad Request | Request format or parameters do not meet server requirements |
401 | Unauthorized | Valid identity authentication has not been completed |
403 | Forbidden | The server understands the request but refuses to execute it, a common reason being insufficient permissions |
404 | Not Found | The requested resource does not exist or the address is incorrect |
405 | Method Not Allowed | Resource does not support the current request method |
500 | Internal Server Error | An error occurred in the server’s internal processing |
502 | Bad Gateway | Gateway or proxy received an invalid response from upstream server |
4xx usually indicates that there is a problem with the client request, and 5xx usually indicates that there is a problem when the server is processing the request.
Common response headers
| response head | action |
|---|---|
Content-Type | declares the data type and character encoding of the response body |
Content-Length | declares response body length |
Location | is often used for redirection to specify a new resource address |
Set-Cookie | requires the browser to store cookies according to the rules |
Cookies in requests use the Cookie request header, and the server uses the Set-Cookie response header when setting cookies.
HTTPS protocol
Overview of HTTPS
HTTPS can be understood as transmitting HTTP over a TLS secure channel. SSL is the historical predecessor of TLS, and relevant certificates are still often referred to as SSL Certificates in daily materials.
TLS mainly provides the following security capabilities:
-
Confidentiality: Encrypt transmitted data to reduce the risk of content being eavesdropped.
-
Integrity: Detects whether the transmission content has been tampered with.
-
Authentication: Verify the identity of the server through a digital certificate; you can also verify the identity of the client in specific scenarios.
Difference between HTTP and HTTPS
| Comparison Items | HTTP | HTTPS |
|---|---|---|
| default port | 80 | 443 |
| transmission protection | Not encrypted by default | Use TLS encryption and verify integrity |
| identity authentication | The agreement itself does not provide certificate certification | Server identity is usually verified through a digital certificate |
| address prefix | http:// | https:// |
Using HTTPS does not mean that the business system is absolutely secure. Servers still need to correctly handle identity authentication, authority control, input verification and sensitive data storage.
Configuring Tomcat in IntelliJ IDEA
The following steps apply to traditional Maven Web projects. Menu names may differ slightly in different versions of IntelliJ IDEA.
Step 1: Create the Maven Web Project
Create the Maven project and prepare the Web resource catalog and Servlet-related dependencies.
Step 2: Configure Web Facet
Open Project Structure, add or review the web configuration in Faces, and then apply the settings.
Step 3: Add Tomcat running configuration
Open Edit Configuration in the Run menu and add the Local configuration under Tomcat Server.

Step 4: Deploy the project Artifact
Add the Artifact of the current Web project to the Deployment page of Tomcat’s run configuration and check the application context path.


Step 5: Launch and access the project
Start Tomcat, verify that there are no deployment errors in the console, and then access in the browser:
http://localhost:8080/pjt0721/index.html
pjt0721 is the application context path, and index.html is the resource to be accessed. The actual address should be consistent with the deployment configuration.
If you enjoyed this, leave a comment~