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 Persistent connections are supported by default, so they cannot simply be 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.1The 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. form uses method="post" 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 header | role |
|---|---|
Accept | Declare the type of response content that the client can receive |
Accept-Language | Language that declares client preferences |
Content-Type | Declare the data type of the request body |
Cookie | Send qualified cookies to the server |
Common request body types
Form coding
Content-Type: application/x-www-form-urlencodedExample of request body:
username=tom&password=123file upload
Content-Type: multipart/form-dataThis format allows you to submit ordinary fields and file content in the same request, and the actual request header will also contain a boundary。
XML
Content-Type: application/xmlJSON
Content-Type: application/jsonJSON 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 OKHTTP 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 | The request format or parameters do not meet the 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,5xx Usually indicates that there was a problem with the server processing the request.
Common response headers
| response header | role |
|---|---|
Content-Type | Declare the data type and character encoding of the response body |
Content-Length | Declare the response body length |
Location | Commonly used for redirection, specifying a new resource address |
Set-Cookie | Require the browser to save cookies in accordance with the rules |
Use of cookies in requests Cookie Request header, used when the server sets cookies Set-Cookie Response head.
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.
-
identity 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 item | 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.htmlwherein pjt0721 is the application context path,index.html Is the resource to access. The actual address should be consistent with the deployment configuration.
If you enjoyed this, leave a comment~