This paper is participating in theNetwork protocols must be known and must be known”Essay campaign

preface

Feel this half year to come, nuggets of activity is one after another 🎁

Today, I see that the Creators Center has added a technical topic essay activity, about network protocol, and one of the comments is:

You guys dig a lot of gold, but I don’t know that

That really speaks for me 😒…… For me, the network protocol has always been both familiar and strange, more strange, because I’ve been listening to it but haven’t really taken the time to learn about it, and it’s really hard to write about

However, the back of a second thought, is not just to learn ah, so plan to take advantage of the activity, wrote this article

Don’t ask me why I chose HTTP, just a little bit familiar with it

Note:

  • Due to theHTTPThis article is mainly about literacy. Please turn left to πŸ‘ˆπŸ»
  • This article mainly refers to encyclopedia andrunoobAnd other online resources

Further down is the main content of this article

What is the HTTP protocol

HTTP stands for Hyper Text Transfer Protocol, which is used to Transfer hypertext from the World Wide Web server to the local browser. It is based on the TCP/IP communication Protocol to Transfer data

Simply put, it is a convention, a convention between the client and the server

The summary is as follows:

The working principle of

The HTTP protocol works between the client and the server. Generally, the browser sends all requests to the HTTP server via THE URL as the HTTP client, and the WEB server sends response information to the client based on the received requests

The specific process can be divided into the following four steps:

A few points to note:

  • HTTPLimit each connection to one request. The server disconnects after processing the request and receiving the reply from the customer
  • HTTPIs media independent: Any type of data can be sent over HTTP as long as the client and server know what to do with the data content. The client and server specify the appropriateMIME-typeContent type
  • HTTPYes stateless: Stateless means that the protocol has no memory for transaction processing. The lack of state means that if the previous information is needed for subsequent processing, it must be retransmitted, which can result in an increase in the amount of data transferred per connection. On the other hand, the server responds faster when it doesn’t need the previous information

The communication process is as follows:

Request and reply packets

HTTP packets can be understood as things that are sent, and there are two types of packets: request packets from the client to the server, and response or reply packets from the server to the client

  • The format of the request packet is as follows:

Request line – General information Header – Request Header – Entity Header – Message body

The request line begins with a method field, followed by a URL field and an HTTP protocol version field, respectively, and ends with CRLF. SP is the separator. Except that CF and LF are required in the final CRLF sequence, nothing else is necessary. See the documentation for details on generic headers, request headers, and entity headers

  • The reply packet format is as follows:

Status line – General message Header – Response Header – Entity Header – Message body

A status code consists of three digits that indicate whether a request is understood or fulfilled. Cause analysis is a short description of the status code of the original text, the status code is used to support automatic operation, and cause analysis is used by users. The client does not need to check or display the syntax. See the documentation for more information on generic headers, response headers, and entity headers

The summary is as follows:

Nine request modes

HTTP1.0 defines three Request methods: GET, POST, and HEAD. HTTP1.1 adds six new Request methods: OPTIONS, PUT, PATCH, DELETE, TRACE, and CONNECT methods

  • GET: makes a request to a specific resource
  • POST: Submits data to a specified resource for processing requests (such as submitting a form or uploading a file). The data is contained in the request body.POSTThe request may result in the creation of new resources and/or the modification of existing resources
  • HEAD: Asks the server for a response that matches the GET request, except that the response body will not be returned. This method allows you to retrieve the meta information contained in the response header without having to transfer the entire response content
  • OPTIONS: Returns the HTTP request method supported by the server for a specific resource. You can also test the functionality of the server using requests sent to the Web server
  • PUT: Uploads the latest content to the specified resource location
  • PATCH: it is to PUTMethod supplement for local updates to known resources
  • DELETE: Requests the server to delete the resource identified by request-uri
  • CONNECT:HTTP / 1.1The protocol is reserved for proxy servers that can pipe connections
  • TRACE: Displays the requests received by the server for testing or diagnosis

Get and POST are commonly used in practical applications

Response header information

Response header information

  • Allow: Which request methods (GET, POST, etc.) are supported by the server
  • Content-Encoding: Document encoding (Encode) method
  • Content-Length: indicates the content length
  • Content-TypeWhat MIME type does the following document belong to
  • Date: Indicates the CURRENT GMT time
  • Expires: When should a document be considered expired
  • Last-Modified: Time when the document was last modified
  • LocationWhere should the customer fetch the document
  • Refresh: indicates how long after the browser should refresh the document, in seconds
  • Server: Server name
  • Set-Cookie: Sets the Cookie associated with the page
  • WWW-Authenticate: What type of Authorization information should the customer provide in the Authorization header

Status code

When a visitor visits a web page, the visitor’s browser makes a request to the server where the page is located. When the browser receives and displays a web page, the server on which the web page is located returns a header containing an HTTP status code in response to the browser’s request

Common HTTP status codes

I’ve combed it out before, as follows

  • 100 Continue To continue. The client should continue with its request
  • 101 Switching Protocols Switch protocol. The server switches protocols based on client requests. You can only switch to a more advanced protocol, for example, the new version of HTTP
  • 200 OKThe request succeeded. Commonly used in GET 与 POSTrequest
  • 201 CreatedHas been created. The new resource was successfully requested and created
  • 202 AcceptedHas been accepted. The request has been accepted, but processing is not complete
  • 203 Non-Authoritative InformationUnauthorized information. The request succeeded. But the returnedmeta The information is not on the original server, but a copy
  • 204 No Content No content. The server processed successfully, but did not return content. You can ensure that the browser continues to display the current document without updating the web page
  • 205 Reset Content Reset the content. The server is successful, and the user end (for example, browser) should reset the document view. Use this return code to clear the browser’s form field
  • 206 Partial Content Part of the content. The server successfully processed part of itGETrequest
  • 300 Multiple Choices A variety of options. The requested resource can include multiple locations, and a list of resource characteristics and addresses can be returned for user terminal (e.g., browser) selection
  • 301 Moved PermanentlyPermanently move. The requested resource has been permanently moved to newURI, the return message will include the newURI, the browser will automatically redirect to newURI. Any future new requests should be made with new onesURIInstead of
  • 302 Found Temporary move. with301 Similar. But resources are moved only temporarily. The client should continue to use the original URI
  • 303 See OtherLook at other addresses. with 301Similar. useGET ε’ŒPOSTRequests to see
  • 304 Not ModifiedUnmodified. The requested resource is not modified, and the server does not return any resources when it returns this status code. Clients typically cache accessed resources by providing a header indicating that the client wants to return only resources that have been modified after a specified date
  • 305 Use ProxyUse a proxy. The requested resource must be accessed through a proxy
  • 306 Unused Has been abandoned HTTPStatus code
  • 307 Temporary RedirectTemporary redirect. with302Similar. useGET Request redirection
  • 400 Bad RequestClient request syntax error, server cannot understand
  • 401 UnauthorizedThe request requires user authentication
  • 402 Payment Required Reserved for future use
  • 403 ForbiddenThe server understands the request from the requesting client, but refuses to execute the request
  • 404 Not Found The server could not find the resource (web page) based on the client’s request. With this code, a web designer can set up a personalized page that says “the resource you requested could not be found.
  • 405 Method Not AllowedThe method in the client request is disabled
  • 406 Not AcceptableThe server could not complete the request based on the content nature of the client request
  • 407 Proxy Authentication RequiredThe request requires the identity of the broker, similar to the 401, but the requester should use the broker for authorization
  • 408 Request Time-outThe server waited for a request sent by the client for a long time and timed out. Procedure
  • 409 ConflictThe server may return this code after completing a PUT request from the client. A conflict occurred when the server processed the request
  • 410 Gone The resource requested by the client does not exist. 410 differs from 404 in that if a resource previously had a 410 code that is now permanently deleted, the site designer can specify a new location for the resource through the 301 code
  • 411 Length RequiredThe server could not process the no-band sent by the client Content-LengthRequest information for
  • 412 Precondition FailedA prerequisite error occurred when the client requested information
  • 413 Request Entity Too LargeThe request was rejected because the requested entity was too large for the server to process. To prevent continuous requests from clients, the server may close the connection. It contains one if the server is temporarily unable to process it Retry-AfterResponse information of
  • 414 Request-URI Too Large The request ofURIFor too long,URIUsually url), the server cannot process
  • 415 Unsupported Media TypeThe server could not process the media format attached to the request
  • 416 Requested range not satisfiableThe scope requested by the client is invalid
  • 417 Expectation FailedThe server cannot meet the requirementsExpect Request header information of
  • 500 Internal Server ErrorThe server had an internal error and could not complete the request
  • 501 Not Implemented The server did not support the requested functionality and could not complete the request
  • 502 Bad GatewayThe server working as a gateway or proxy received an invalid response from the remote server when attempting to execute the request
  • 503 Service UnavailableThe server is temporarily unable to process client requests due to overloading or system maintenance. The length of the delay can be included in the serverRetry-After In the header
  • 504 Gateway Time-out The server acting as a gateway or proxy did not get the request from the remote server in time
  • 505 HTTP Version not supportedThe server did not support the requestHTTP Protocol version, unable to complete processing

Status code classification

The HTTP status code consists of three decimal digits. The first decimal digit defines the type of the status code, and the second two digits do not classify

HTTP status codes are classified into five types:

  • 1 * *Message, the server receives the request and requires the requester to proceed with the operation
  • 2 * *Success, the operation is received and processed successfully
  • 3 * *Redirect, requiring further action to complete the request
  • 4 * *Client error, request contains syntax error or request cannot be completed
  • 5 * *Server error. The server encountered an error while processing the request

Content type

Content Type refers to the content-Type, which generally refers to the Content Type in the web page. It defines the Type of the web file and the code of the web page. It determines in what form and in what code the browser will read the file

Syntax format:

Content-Type: text/html; charset=utf-8
Content-Type: multipart/form-data; boundary=something
Copy the code

Media format type

There are many types of media formats, mainly divided into the following categories:

Common media format classes

  • text/htmlHTML format:
  • text/plain: Plain text format
  • text/xmlThe XML format:
  • image/gif: GIF format
  • image/jpeg: JPG format
  • image/png: PNG image format

The media format type that begins with Application

  • application/xhtml+xmlXHTML format:
  • application/xml: XML data format
  • application/atom+xml: Atom XML aggregation format
  • application/json: Indicates the JSON data format
  • application/pdfPDF format:
  • application/msword: Word document format
  • application/octet-stream: binary stream data (such as common file downloads)
  • application/x-www-form-urlencoded : < form encType = "" >EncType, the form data is encoded as key/value format and sent to the server (the form’s default submission data format).

Used when uploading files

  • multipart/form-data: This format is used when you need to upload files from a form

For more specific content-Types, refer to the comparison table

END

Well, that’s all for this article. If you have any questions, please point out

reference

  • Baike.baidu.com/item/HTTP/2…
  • www.runoob.com/http/http-t…