The structure of the URI

Uniform Resource Locator abbreviation for Uniform Resource Locator

protocol :// hostname[:port] / path / [;parameters][?query]#fragment

The FORMAT of the URL consists of three parts:

  1. The first part is the agreement (or service mode).
  2. The second part is the IP address (and sometimes port number) of the host hosting the resource.
  3. The third part is the specific address of the host resource, such as directory and file name.

Parts 1 and 2 are separated by a ://, and parts 2 and 3 are separated by a /. The first and second parts are indispensable, and the third part can sometimes be omitted.

Request message Composition

HTTP request packets consist of (request line + request header + request body)

Request method

  • Request method:
    • POST: submits data in json or urlencode format ****
    • GET: GET resources (data format params or query query parameters)
    • HEAD: obtains the meta information of the resource
    • PUT: Modifies data
    • DELETE: deletes data
    • CONNECT: establishes the connection tunnel for the proxy server
    • TRACE: Traces the transmission path of the request and response

GET/POST

1. From the perspective of caching, get requests are actively cached by browsers and leave historical records, while POST requests are not. From an encoding perspective, GET can only urL-encode and only accept ASCII encoding, while POST has no limitation 3. From a parameter perspective, GET is generally placed in the URL and therefore not secureCopy the code

Common content-type type

  • Common text formats
    • The text/HTML: HTML format
    • Text /plain: plain text format
    • Text/XML: XML format
  • Image format
    • Image/GIF: indicates the GIF image format
    • Image/JPEG: JPG format
    • Image/PNG: indicates the PNG image format
  • Audio formats
    • Audio/video, audio/mpeg video/mp4, etc
  • Media format types beginning with Application:
    • Application/XHTML + XML, XHTML format
    • Application/XML :XML data format
    • Application/Atom + XML :Atom XML aggregation format
    • Application /json: Json data format
    • Application/PDF: PDF format
    • Application/MSWORD :Word document format
    • Application /octet-stream: binary stream data (common file download)
    • Application/X-www-form-urlencoded: The default encType in forms, where form data is encoded as key/value format and sent to the server
  • Another common media format is used when uploading files:

Multipart /form-data: This format is used when files need to be uploaded in the form

Response body composition

An HTTP response packet consists of a response line, response header, and response body

Response status code

  • 1xx: indicates that the protocol processing is in the intermediate state and subsequent operations are required.
  • 2xx: indicates that the status is successful.
  • 3xx: Indicates the redirection status. The location of resources changes and a request needs to be made again.
  • 4xx: The request packet is incorrect.
  • 5xx: An error occurs on the server.

Common response status code

  • 101 Switching separate Protocols. When HTTP is upgraded to WebSocket, the server sends status code 101 if it agrees to the change.
  • 2xx
    • 200 OK is the most seen success status code. There is usually data in the response body.
    • 204 No Content Has the same meaning as 200, but there is No body data after the response header.
    • 206 Partial Content as the name implies, Partial Content is used for HTTP block download and breakpoint continuation. Of course, it also includes the corresponding content-range response header field.
  • 3xx
    • 301 Moved Permanently, corresponding to 302 Found Permanently.
    • 304 Not Modified: This status code is returned when the negotiated cache is hit. See browser cache for details.
  • 4xx
    • 400 Bad Request: Developers often see confusion, just a general error, and don’t know what went wrong.
    • 403 Forbidden: This does not mean that the request packet fails, but that the server forbids access for many reasons, such as legal prohibition and sensitive information.
    • 404 Not Found: Indicates that the resource is Not Found on the server.
    • 405 Method Not Allowed: The request Method is Not Allowed by the server.
    • 406 Not Acceptable: The resource does Not meet the requirements of the client.
    • 408 Request Timeout: The server waits too long.
    • 409 Conflict: Multiple requests are in Conflict.
    • 413 Request Entity Too Large: The Request body data is Too Large.
    • 414 request-uri Too Long: The URI in the Request line is Too large.
    • 429 Too Many Request: The client sends Too Many requests.
    • 431 Request Header Fields Too Large The Fields in the Request Header are Too Large.
  • 5xx
    • 500 Internal Server Error: The Server failed.
    • 501 Not Implemented: The functions requested by the client are Not supported.
    • 502 Bad Gateway: The server itself is normal, but there was an error when accessing the server.
    • 503 Service Unavailable: The server is busy and cannot respond to services temporarily.

Links: juejin. Cn/post / 684490…