What is the http protocol? What is the difference between Get and post requests? What are the HTTP request content-Types? What scenarios are HTTP suitable for? What are the http status codes?

What is http - Tencent Video

1. Background introduction

What is the http protocol?

The HTTP protocol is an object-oriented protocol belonging to the application layer. HTTP is the abbreviation of Hypertext Transfer Protocol.

http is a communication protocol based on TCP/IP to transfer data (html files, image files, query results, etc.)

The http protocol works on the client-server architecture. The browser sends all requests to the HTTP server, that is, the web server, through the http client through the URL. The web server sends response information to the client according to the received request.

2. Knowledge analysis

Features of http protocol

1. Simple and fast: When a client requests a service from the server, it only needs to transmit the request method and path. Commonly used request methods are GET, HEAD, and POST. Each method specifies a different type of contact between the client and the server. Because the HTTP protocol is simple, the program scale of the HTTP server is small, so the communication speed is fast.

2. Flexible: HTTP allows the transmission of data objects of any type. The type being transferred is marked by Content-Type.

3. Connectionless: The meaning of connectionless is to limit the processing of only one request per connection. After the server processes the client's request and receives the client's response, it disconnects. In this way, transmission time can be saved.

4. Stateless: The HTTP protocol is a stateless protocol. Stateless means that the protocol has no memory capability for transaction processing. The lack of state means that if previous information is required for subsequent processing, it must be retransmitted, potentially resulting in an increased amount of data transferred per connection. On the other hand, the server responds faster when it does not need the previous information.

What is the difference between get and post requests?

Get and post are two different implementations of the http protocol. Get means that the server obtains the required parameters from the url, and get can see the parameters. Post actively sends parameters to the server, so these parameters are generally invisible.

The get method is usually used to request the server to send a certain resource, and the post method is usually used to support html forms. The data filled in the form is usually sent to the server, and then the server sends it to where he wants to go.

What are the HTTP request content-Types?

There are generally three types of Content-Type in Http Header:

application/x-www-form-urlencoded: Data is encoded as name/value pairs, which is the standard encoding format

multipart/form-data: data is encoded as a message, each control on the page corresponds to a part in the message

text/plain: The data is encoded in plain text, which does not contain any space or format characters, and is marked RAW in the postman software

What scenario is http suitable for?

Company OA service, Internet service

3. Frequently Asked Questions

1: What are the advantages and disadvantages of http?

2: What are the status codes of http

4. Solutions

Advantages of http:

1: Based on application-level interface, easy to use

2: The required development level is not high, and the fault tolerance is strong

Disadvantages of http:

1: The transmission speed is slow and the data packet is large

2: If you want to achieve real-time interaction, the server performance pressure is high

3: Poor data transmission security

What are the http status codes?

There are many http status codes, so I won't give examples one by one, and give a general concept

The 1 header represents the message, which means that the request has been received and needs to continue processing. This type of response is only a temporary response.

The 2-header represents success, this type of status code represents that the request has been successfully received by the server, understand

The 3-header represents redirection. This type of status code indicates that the client needs to take further action to complete the request. Usually, these status codes are used for redirection, and the subsequent address (redirection target) is indicated in the location field of this response.

The 4-header represents a request error. This type of status code indicates that the client may appear to have an error, preventing the server from processing.

The 5-header means that the server has an error or an abnormal state in the process of processing the request.

5. Coding practice

6. Think outside the box

What are the meanings of the status codes we often encounter?

200: The request has succeeded, and the response headers or data bodies expected by the request will be returned with this response.

403: The server understood the request, but refused to execute it.

404: The request failed, the requested resource was not found on the server. The 404 status code is widely used when the server does not want to reveal why the request was rejected or no other suitable response is available. The most likely reason for this error is that the page is not available on the server side.

405: The request method specified in the request line cannot be used to request the corresponding resource. The response MUST return an Allow header indicating the list of request methods that the current resource can accept. In view of the PUT and DELETE methods, the resources on the server will be written, so most web servers do not support or do not allow the above request methods under the default configuration, and will return 405 errors for such requests.

500: The server encountered an unexpected condition that prevented it from completing the processing of the request. Generally, this problem occurs when there is an error in the source code on the server side.

503: The server is currently unable to process the request due to temporary server maintenance or overload. This condition is temporary and will return after a period of time.

7. References

Baidu

8. More discussion

thanks

Thanks for watching, please correct me if there is any mistake


Guess you like

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