HTTP Introduction

HTTP protocol is the Hyper Text Transfer abbreviation Protocol (Hypertext Transfer Protocol) is used from the World Wide Web (WWW: World Wide Web) server to transfer hypertext transfer protocol local browser.

1, HTTP works

HTTP is used to transfer a data (HTML files, image files, query results, etc.) based on TCP / IP communication protocol.
HTTP protocol works on the client - server architecture on. Browser as an HTTP client URL that is WEB server sends all requests to the server via HTTP.

There are Web server: Nginx, Apache server, IIS server (Internet Information Services) and so on.

Web server according to the received request, transmits the response information to the client.

The default HTTP port number is 80, but you can also be changed to 8080 or other ports.
HTTP Three things to note:

  • HTTP is a connectionless: Meaning No limitation is attached only one request per connection. After the server processes client requests and receives the customer's response, i.e., disconnected. In this way it can save transmission time.
  • HTTP is an independent media: This means that only the client and the server knows how to handle the data content of any type of data can be sent via HTTP. The client and server specify the appropriate MIME-type content type.
  • HTTP is a stateless: HTTP protocol is stateless protocol. No state is no protocol for transaction processing and memory. If the lack of state means that the subsequent processing required in front of the information, it must be retransmitted, which may result in the amount of data transmitted for each connection is increased. On the other hand, when it does not require previous information in response to a faster server.

The following chart shows the HTTP protocol communication flow:
Here Insert Picture Description

2, HTTP message structure

HTTP is the client / server (C / S) model framework to exchange information via a secure link is a stateless request / response protocol.

A HTTP "client" is an application (Web browser or any other client), the purpose of the transmission of one or more HTTP request to the server by connecting to the server.

A HTTP "server" is also an application (typically a Web service, such as Nginx, Apache Web Server or IIS server, etc.), by receiving the client's request is sent to the client HTTP response data.

HTTP uses uniform resource identifier (Uniform Resource Identifiers, URI) to transmit data and establish a connection.

3, client request message

The client sends a request to the HTTP server request message comprises the following format: The general format of the request line (request line), the request header (header), a blank line, and a data portion composed of four requests, the figure shows the request packet .

( Https://www.baidu.com/s?ie=UTF-8&wd=QQ music , this link can see the contents of the request header)

Here Insert Picture Description
Here Insert Picture Description

4, server response message

HTTP response also consists of four parts, namely: a status line, message header, and response body blank line.
Here Insert Picture Description
Examples

The following example is typical that passed using the GET instance data:

Client requests:

Connected to www.testpm.cn (47.244.247.240) port 80 (#0)
> GET /hello.txt HTTP/1.1   # 请求方式、URL、版本协议。
> User-Agent: curl/7.29.0   #用什么客户端访问
> Host: www.testpm.cn  #主机名,域名。主机和端口号,
> Accept: */*  #匹配什么文件类型,“*” 是通用匹配。匹配所有类型

Server response:

< HTTP/1.1 200 OK       #请求返回的状态码
< Server: nginx/1.16.0  #请求的服务和版本号
< Date: Thu, 04 Jul 2019 08:19:40 GMT
< Content-Type: text/plain #文本类型,有html,plain:普通文本
< Content-Length: 12
< Last-Modified: Thu, 04 Jul 2019 08:13:25 GMT
< Connection: keep-alive  #是否支持长连接
< ETag: "5d1db525-c"  #标识,每次访问如果与最开始的一样返回304否则校验不一致返回200
< Accept-Ranges: bytes

5, HTTP request method

The standard HTTP, HTTP request can use several request methods.

HTTP1.0 request defines three methods: GET, POST, and HEAD method.

HTTP1.1 five new request methods: OPTIONS, PUT, DELETE, TRACE, and CONNECT method.

Key methods:

GET: simple data acquisition (acquire an index.html page)

POST: upload / create a file (generate new data)

PUT: Save data (covering / update files, pictures, etc., will not produce new data)

DELETE: Delete
Here Insert Picture Description

6, HTTP response headers

HTTP request header provides information about the request, response, or other transmission entities.

In this section we will introduce specific HTTP response header information.
Here Insert Picture Description
Here Insert Picture Description

Published 48 original articles · won praise 18 · views 3662

Guess you like

Origin blog.csdn.net/wx912820/article/details/104782692