preface

  • About computer networks,HTTPNetwork communication protocols are very important in any development work
  • Today, I will offer oneHTTPI hope you like it

directory


1. Stock up on knowledge

Before explaining the HTPP protocol, learn some basic computer network knowledge

1.1 Computer network architecture

  • Defines the layers of a computer network + its set of protocols

  • Function Defines the functions that the computer network can perform

  • The computer network architecture is divided into three kinds: OSI architecture, TCP/IP architecture and five layer architecture

    • OSIArchitecture: conceptually clear & ideologically complete, but complex & impractical
    • TCP / IPArchitecture: contains a set of network protocols that form the basis of the InternetInternetThe core protocol is widely used in LAN and WAN
    • Five-tier architecture: FusedOSITCP / IPArchitecture for learning & explaining computer principles

  • TCP / IPA detailed introduction to the architecture of

    Due to theTCP / IPThe architecture is more extensive, so the main explanation

1.2 Basic model of HTTP protocol communication

  • HTTPThe basis of protocol transmission:TCP/IPProtocol model

  • HTTP belongs to the highest application layer


2. Introduction

Next, take a brief look at HTTP


3. Working mode

  • HTTPDeal withRequest/ResponseThe way in which
  • The specific working process is as follows:


4. HTTP packet details

  • HTTPData exchange at the application layer = packets
  • HTTPAre classified into request packets and response packets


    When sending a request and when responding to a request

  • The following describes the two types of packets in detail

4.1 Request Message

4.1.1 Message Structure

  • HTTPThe request message is sent byRequest line, request header & request bodyComposition, as shown below

  • Each component is described in detail below

4.1.2 Structure Details

Component 1: Request line
  • Function declaration request method, host name, resource path & protocol version

  • Structure request line composition = request method + request path + protocol version

    Note: Spaces cannot be omitted

  • Composition is introduced

The difference between GET and PSOT methods is specified here:

GET/CHN /yxsz/index.htm HTTP/1.1

Component 2: Request header
  • Function: Declare some information about the client, server, or packet
  • Usage: Use the “header: value” format
  • Common request Headers 1. Common Headers of request and response packets

2. Common request Headers

  • Example: (URL: www.tsinghua.edu.cn/chn/yxsz/in.) Host: www.tsinghua.edu.cn (indicates the Host domain name) User-agent: Mozilla/5.0 (indicates that the User Agent uses the Netscape browser)
Composition 3: Request body
  • Function: Stores data to be sent to the server

    Optional parts, such as GET requests, have no request data

  • Usage: 3 kinds in total

At this point, the explanation about the request line, request header and request body of the request message is finished.

4.1.3 summary

  • The following table summarizes the request message

  • Sample Request message

4.2 HTTP Response Packets

4.2.1 Packet Structure

  • HTTPThe response message contains status line, response header and response body

  • The response header and body are similar to the request header and body of the request packet
  • The biggest difference between the two types of messages is the status line and the request line

Each component is described in detail below

4.2.2 Structure Details

Component 1: status line

  • Description Protocol version, status code, and status code description
  • composition

    The status line consists of protocol version, status code and status information


    Where, Spaces cannot be saved



  • Detailed introduction

  • Example status line HTTP/1.1 202 Accepted, HTTP/1.1 404 Not Found

Component 2: Response header

  • Function: Declare some information about the client, server, or packet
  • Usage: Use the “header: value” format
  • Common request Headers 1. Common Headers of request and response packets

2. Common response headers

Component 3: response body

  • Function: Stores data to be returned to the client
  • Usage: consistent with the request body, also divided into: any type of data exchange format, key-value pair form and partial form

4.2.3 Summary of Response Packets

4.3 summarize

The following two message structures are briefly summarized


5. Extra knowledge

Here are some additional facts about HTTP:

  • HTTP1.1HTTP1.0The difference between
  • HTTPHTTPSThe difference between
  • HTTPThe way to handle long connections

5.1 Differences between HTTP1.1 and HTTP1.0

Http1.1 has the following advantages over Http1.0:



  • Introduce persistent connections, that is, in the sameTCPCan transmit more than oneHTTPRequest & Response
  • Multiple requests & responses can occur simultaneously and overlap
  • Introduce more request & response headers

For example, HTTP1.0 does not have the host field related to authentication, state management, and Cache

5.2 Differences between HTTP and HTTPS

5.3 How to Process Long Connections using HTTP


6. Summary

  • This article summarizes comprehensivelyHTTPBasic knowledge of
  • And I’m going to continue with thatAndroidRelevant knowledge in development, interested can continue to pay attention toCarson_Ho android Development Notes

Please give me a thumbs up! Because your encouragement is my biggest motivation to write!