Home > Common Problem > body text

Detailed explanation of HTTP protocol

清浅
Release: 2019-03-20 14:01:47
Original
3638 people have browsed it

HTTP protocol is the Hypertext Transfer Protocol, which is mainly used to transfer hypertext from the server to the local browser. It consists of four parts: request line, request header, blank line and request data.

HTTP request message is divided into four parts: request line, request header, blank line and request data. Next, these four parts will be introduced in detail in the article, which has certain reference value and I hope it will be helpful to everyone.

Detailed explanation of HTTP protocol

[Recommended course: HTTP course]

Introduction to HTTP

HTTP protocol is the abbreviation of Hyper Text Transfer Protocol, which is a transfer protocol used to transfer hypertext from the World Wide Web server to the local browser.
It is a communication protocol based on TCP/IP to transmit data

HTTP working principle

(1) HTTP is connectionless: connectionless refers to Limit each connection to only one request. That is, after the server processes the user's request and receives the user's response, it disconnects the connection. This saves transmission time.

(2) HTTP is media independent: As long as the client and server know how to process the data content, any type of data can be sent through HTTP. Clients and servers specify the appropriate MIME-type content type to use.

(3) HTTP is stateless: The HTTP protocol is a stateless protocol. A stateless protocol means that it has no memory for transaction processing. If subsequent processing requires the previous information, it must be retransmitted, which results in an increase in the amount of data transmitted per connection. But there is also an advantage that when the server does not need the previous information, its response is faster

HTTP composition

Request line:

The request line consists of three parts: the request method field, the URL field and the HTTP protocol version, which are separated by spaces. For example,

GET /index.html HTTP/1.1
Copy after login

request method defines a total of 8 methods: GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS, TRACE, but the most commonly used methods are the GET method and the POST method, because currently most Most browsers only support GET and POST methods

Request header:

The request header is composed of keyword/value pairs, one pair per line, key Words and values ​​are separated by English colon ":". Request headers inform the server about the client's request.

Typical request headers are:

User-Agent: the browser type that generated the request

Accept: a list of content types recognized by the client

Host: The requested host name, allowing multiple domain names to be at the same IP address, that is, a virtual host.

Example:

Host: localhost
Copy after login

Empty line

After the last request header is an empty line, send carriage return and line feed characters, and notify the server of the following No more request headers

Request data

The request data is not used in the GET method, but in the POST method. The POST method is suitable for situations where customers are required to fill out a form.

The most commonly used request headers related to request data are Content-Type and Content-Length.

Example:

Content-Type: application/json;charset=utf-8
Copy after login

Summary: The above is the entire content of this article, I hope it will be helpful to everyone learning http

The above is the detailed content of Detailed explanation of HTTP protocol. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!