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 the
HTTP
This article is mainly about literacy. Please turn left to ππ» - This article mainly refers to encyclopedia and
runoob
And 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:
HTTP
Limit each connection to one request. The server disconnects after processing the request and receiving the reply from the customerHTTP
Is 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-type
Content typeHTTP
Yes 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 resourcePOST
: 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.POST
The request may result in the creation of new resources and/or the modification of existing resourcesHEAD
: 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 contentOPTIONS
: 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 serverPUT
: Uploads the latest content to the specified resource locationPATCH
: it is toPUT
Method supplement for local updates to known resourcesDELETE
: Requests the server to delete the resource identified by request-uriCONNECT
:HTTP / 1.1
The protocol is reserved for proxy servers that can pipe connectionsTRACE
: 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 serverContent-Encoding
: Document encoding (Encode) methodContent-Length
: indicates the content lengthContent-Type
What MIME type does the following document belong toDate
: Indicates the CURRENT GMT timeExpires
: When should a document be considered expiredLast-Modified
: Time when the document was last modifiedLocation
Where should the customer fetch the documentRefresh
: indicates how long after the browser should refresh the document, in secondsServer
: Server nameSet-Cookie
: Sets the Cookie associated with the pageWWW-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
OK
The request succeeded. Commonly used inGET
δΈPOST
request - 201
Created
Has been created. The new resource was successfully requested and created - 202
Accepted
Has been accepted. The request has been accepted, but processing is not complete - 203
Non-Authoritative Information
Unauthorized 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 itGET
request - 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 Permanently
Permanently 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 onesURI
Instead of - 302
Found
Temporary move. with301
Similar. But resources are moved only temporarily. The client should continue to use the original URI - 303
See Other
Look at other addresses. with301
Similar. useGET
εPOST
Requests to see - 304
Not Modified
Unmodified. 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 Proxy
Use a proxy. The requested resource must be accessed through a proxy - 306
Unused
Has been abandonedHTTP
Status code - 307
Temporary Redirect
Temporary redirect. with302
Similar. useGET
Request redirection - 400
Bad Request
Client request syntax error, server cannot understand - 401
Unauthorized
The request requires user authentication - 402
Payment Required
Reserved for future use - 403
Forbidden
The 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 Allowed
The method in the client request is disabled - 406
Not Acceptable
The server could not complete the request based on the content nature of the client request - 407
Proxy Authentication Required
The request requires the identity of the broker, similar to the 401, but the requester should use the broker for authorization - 408
Request Time-out
The server waited for a request sent by the client for a long time and timed out. Procedure - 409
Conflict
The 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 Required
The server could not process the no-band sent by the clientContent-Length
Request information for - 412
Precondition Failed
A prerequisite error occurred when the client requested information - 413
Request Entity Too Large
The 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 itRetry-After
Response information of - 414
Request-URI Too Large
The request ofURI
For too long,URI
Usually url), the server cannot process - 415
Unsupported Media Type
The server could not process the media format attached to the request - 416
Requested range not satisfiable
The scope requested by the client is invalid - 417
Expectation Failed
The server cannot meet the requirementsExpect
Request header information of - 500
Internal Server Error
The 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 Gateway
The server working as a gateway or proxy received an invalid response from the remote server when attempting to execute the request - 503
Service Unavailable
The 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 supported
The 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 operation2 * *
Success, the operation is received and processed successfully3 * *
Redirect, requiring further action to complete the request4 * *
Client error, request contains syntax error or request cannot be completed5 * *
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/html
HTML format:text/plain
: Plain text formattext/xml
The XML format:image/gif
: GIF formatimage/jpeg
: JPG formatimage/png
: PNG image format
The media format type that begins with Application
application/xhtml+xml
XHTML format:application/xml
: XML data formatapplication/atom+xml
: Atom XML aggregation formatapplication/json
: Indicates the JSON data formatapplication/pdf
PDF format:application/msword
: Word document formatapplication/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…