Network Protocol HTTP protocol (I)


HTTP protocol  It’s a kind ofStatelessApplication layer, toRequest / replyIt uses extensible semantics and self describing message format, and network-basedHypertext informationThe system interacts flexibly.

1. Schematic diagram of HTTP request scenario

Network Protocol HTTP protocol (I)

Network Protocol HTTP protocol (I)

2. Flow chart of HTTP request initiated by browser

Network Protocol HTTP protocol (I)

3. Schematic diagram of DNS resolution process

DNS resolutionThe purpose of domain name string is to correspond to the domain name string  IP address  Get it. With this  IP address  Then you can  IP addressThe corresponding computer initiated the communication:

3.1 schematic diagram of DNS resolution process

Network Protocol HTTP protocol (I)

3.2 DNS resolution flow chart

Network Protocol HTTP protocol (I)

4. Build HTTP request

The above steps are obtained  ipAfter the address  ipThe address completes three handshakesTCP  Connect (the content of TCP connection will be introduced in subsequent articles), and then you can build itHTTPRequest, populating context toHTTP header, re launch  HTTPRequest, which will be involved at this time  HTTP  The format of the protocol is described belowHTTP protocol format based on ABNF language description

4.1 format diagram of HTTP protocol

Network Protocol HTTP protocol (I)

Tips: to describe the HTTP format in the figure, you need to formulate a strict specification. Usually, the HTTP protocol is based on  ABNF  Language to strictly define.

4.2 ABNF (extended Bakos nauer normal form) operator

  • (1) White space character (SP): used to separate the elements in the protocol definition

    method SP request-target SP HTTP-version CRLF
  • (2) Select (/): indicates the rules that can be selected

    start-line = request-line / status-line
  • (3) Range value (% c##-##)

    Octal = "0" / "1" / "2" / "3" / "4" / "5" / "6" / "7" is equivalent to octal =% x30-37
  • (4) Sequence combination (()): combine rules as a single element
  • (5) Non quantitative repetition (m * n)

    *Represents 0 or more elements: * (header field CRLF)
    1 * indicates one or more elements; 2 * 4 indicates 2-4 elements
  • (6) Optional sequence ([])


4.3 ABNF (extended Bakos nauer paradigm) rule table

Listed below  ABNF  Character rules and meanings of Description:

Listed belowABNFCharacter rules and meanings of Description:

rule Definition form meaning
ALPHA %x41-5A / %x61-71 Upper and lower case letters (A-Z, A-Z) asscii
DIGIT %x30-39 Number 0-9
HEXDIG DIGIT / “A” / “B” / “C” / “D” / “E” / “F” Hexadecimal digits (0-9, A-F, A-F)
DQUOTE %x22 Double quotation mark
SP %x22 Space
HTAB %x09 horizontal tab
WSP SP / HTAB Space or horizontal tab
LWSP *(WSP / CRLF WSP) Straight line blank
VCHAR %x21-7E Visible (print) characters
CHAR %x01-7F Any 7-bit us-ascii character, excluding nul (% X00)
OCTET %x00-FF 8-bit data
CTL %x00-1F / %x7F Control character
CR %0D enter
LF %x0A Line feed
CRLF CRLF Internet standard line feed
BIT “0” / “1” Binary digit

4.4 HTTP protocol format based on ABNF description

HTTP-message = start-line *(header-field CRLF) CRLF [message-body]
    start-line = request-line / status-line
       request-line = method SP request-target SP HTTP-version CRLF
       status-line = HTTP-version SP status-code SP reason-phrase CRLF
    header-field = field-name ":" OWS field-value OWS
       OWS = *(SP / HTAB)
       field-name = token
       field-value = *(field-content / obs-fold)
    message-body = *OCTET

5. Telnet simulates HTTP requests

telnet 80
GET /themes/simpleboot3/portal/public/assets/css/moco.css HTTP/1.1

Return as shown in the figure below:
Network Protocol HTTP protocol (I)

Tips: enter first  telnet 80  Then you will be prompted and  After the connection is successful, you will be prompted to enter the content, and then enter  GET /themes/simpleboot3/portal/public/assets/css/moco.css HTTP/1.1and
Host:  After entering twice, you can see that both the request data and the return data follow the  ABNF  standard.

6. Summary

This paper mainly introduces  HTTP  Request process, and then  DNS  Domain name resolution is described in detail,DNS  Analytical get  ip  After the address, you can complete the classic  TCP/IP  Shake hands, and then you can start  HTTP  Yes, the text is also correct  HTTP  The format specification of the request is introduced,HTTP  The protocol specification is based on  ANBF  A strict definition of language, and finally introduces how to try it out  telnet  Tool simulation  HTTP  Request process.

Scan code and pay attention to eyin Shixian

Network Protocol HTTP protocol (I)