There are several content types for HTTP requests. What is the difference? What scenario is HTTP suitable for? What are the HTTP status codes?

This is the back-end small class of the monastery. Each article is shared from

[background introduction] [knowledge analysis] [common problems] [solutions] [coding practice] [extended thinking] [more discussion] [References]

Eight aspects of in-depth analysis of back-end knowledge / skills. This article shares:

[there are several content types of HTTP requests. What are the differences? What scenarios are HTTP suitable for? What are the HTTP status codes?]

Hello, I'm a java student of Xi'an Branch of it Academy. I'm an honest, pure and kind java programmer. Today, I'd like to share with you what is HTTP protocol? What is the difference between get and post requests? There are several content types for HTTP requests. What is the difference? What scenario is HTTP suitable for? What are the HTTP status codes?

1、 A Background introduction

HTTP (Hypertext Transfer Protocol) is a data transfer protocol that specifies the rules for communication between browsers and World Wide Web (WWW = World Wide Web) servers and transmits World Wide Web documents through the Internet. It is the core content of web system. It is the rule of direct data transmission between web server and client. It can make the browser more efficient and reduce network transmission. It not only ensures that the computer transmits hypertext documents correctly and quickly, but also determines which part of the transmitted document and which part of the content is displayed first (such as text before graphics).

HTTP is an application layer protocol, which consists of request and response. It is a standard client server model. Web server is usually referred to as the website and the publisher of information content.

Web browsing is the main application of HTTP, but this does not mean that HTTP can only be used for web browsing. HTTP is a protocol. As long as both sides of communication abide by this protocol, HTTP can be useful. For example, our commonly used QQ and Xunlei software will use HTTP protocol (including other protocols).

2、 Knowledge analysis

2.1 what is HTTP protocol

The HTTP protocol defines how the web client requests a web page from the web server and how the server transmits the web page to the client. HTTP protocol adopts request / response model. The client sends a request message to the server, which contains the requested method, URL, protocol version, request header and request data. The server responds with a status line, which includes the protocol version, success or error code, server information, response header and response data.

2.2 HTTP request / response steps

HTTP request / response steps:

An HTTP operation is called a transaction, and its working process can be divided into four steps:

1. Connect the client to the web server. First, the client needs to establish a connection with the server. An HTTP client, usually a browser, establishes a TCP socket connection with the HTTP side of the web server (80 by default). For example, as long as you click a hyperlink, the work of HTTP begins.

2. After establishing a connection, send an HTTP request. The client sends a request to the server in the format of uniform resource identifier (URL) and protocol version number, followed by mime information, including request modifier, client information and possible content.

3. The server accepts the request and returns an HTTP response. The web server parses the request and locates the requested resource. The server writes the resource copy to the TCP socket and the client reads it. The format is a status line, including the protocol version number of the information, a success or error code, followed by mime information, including server information, entity information and possible contents.

4. Release the TCP connection. If the connection mode is close, the server actively closes the TCP connection, and the client passively closes the connection and releases the TCP connection; If the connection mode is keepalive, the connection will be maintained for a period of time, and requests can continue to be received within this time;

5. The client browser parses HTML content. The client browser first parses the status line to view the status code indicating whether the request is successful. Then each response header is parsed, and the response header tells the following HTML document and document character set of several bytes. The client browser reads the response data HTML, formats it according to the HTML syntax, and displays it in the browser window.

2.3 HTTP request message request

The request message that the client sends an HTTP request to the server includes the following formats: request line, request header, empty line and request data

Part I: request line, which describes the request type, the resource to be accessed and the HTTP version used

Get indicates that the request type is get, [/ 562f25980001b106000338. JPG] is the resource to be accessed, and the last part of the line indicates that http1.0 is used Version 1

The second part: the request header, the part immediately after the request line (i.e. the first line), is used to describe the additional information to be used by the server

Starting from the second line is the request header, and host will indicate the destination of the request User agent, which can be accessed by server and client scripts, is an important basis for browser type detection logic This information is defined by your browser and sent automatically in each request, etc

Part III: blank line. The blank line behind the request header is required. Even if the request data in the fourth part is empty, there must be empty rows.

Part 4: the request data is also called the subject. Any other data can be added. The request data of this example is empty.

Example of post request

Part I: request line. The first line is the post request and http1 Version 1.

Part II: request header, lines 2 to 6.

Part III: blank line, blank line of the seventh line.

Part 4: request data, line 8.

2.4. HTTP response message response

Generally, the server will return an HTTP response message after receiving and processing the request sent by the client.

The HTTP response also consists of four parts: status line, message header, blank line and response body

Part II: message header, which is used to describe some additional information to be used by the client

The second, third and fourth lines are message headers. Date: the date and time when the response is generated; Content-Type:

HTML (text / HTML) of MIME type is specified, and the encoding type is iso-8859-1

Part III: blank line. The blank line after the message header is required

Part IV: response body, the text information returned by the server to the client.

The HTML part after the blank line is the response body.

2.5 URL details

URL (uniform resource locator) address is used to describe resources on a network. The basic format is as follows

schema://host [:port#]/path/.../ [?query-string][#anchor]

Ppt link video link

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>