Table of contents
8. Introduction to HTTP headers
1. What is http protocol?
http: Hyper Text Transfer Protocol Hyper Text Transfer Protocol is the most widely used network protocol on the Internet and is mainly used for Web services. It is realized by computer processing of text information in the format of HTML (Hyper Text Mark Language).
2.http protocol version?
http 0.9: Only transmit html documents to users
http 1.0 :
1. Introduced the MIME (Multipurpose Internet Mail Extensions) mechanism: Multipurpose Internet Mail Extensions. After the introduction of this technology, http can send multimedia (such as video, audio, etc.) information. This mechanism allows http to no longer only support html format, but can also support other formats for sending.
2. Introduced the keep-alive mechanism to support the persistent connection function (but this keep-alive principle is formed by adding a certain field to the header, and does not support this function natively)
3. Introducing support for caching function http 1.1 supports more request methods, more refined cache control, and natively supports persistent connection function (persistent).
http 2.0 :
Provides HTTP semantic optimized transmission, spdy: a technology introduced by Google, which can accelerate http data interaction, especially using the SSL acceleration mechanism, but spdy is not used much now.
Currently, the commonly used versions are http 1.0 version and http 1.1 version.
3.http text frame
<html>
<head>
<title></title>
</head>
<body>
<h1>hello</h1>
</body>
</html>
4.http request message
1.request Message (request message) client-→ server
The client makes a request to the server, and different websites are used to request different resources (html documents)
2.response Message (response message) server-→ client
The server responds to the client's request
5.http message format
Request line + request header + blank line + request entity
1. Request line
The request line mainly consists of three parts: request method + URL field + HTTP protocol version
composition:
<method>: The method of this request
<request-URL>: The path to the requested resource
<version>: Requested protocol version
http request method:
HTTP request method | describe |
---|---|
GET | Used by the client to request specified resource information and return the entity of the specified resource. |
HEAD | Similar to GET, but does not need to return the resource requested by the client, only the response header is returned (telling the client whether I have it or not) |
POST | Submit data to the server based on HTML forms, usually when data needs to be stored, such as mysql storage |
PUT | Contrary to GET, resources are sent to the server, and the server stores this data, such as Baidu Netdisk and Alibaba Cloud Disk. |
DELETE | Request the server to delete the resource specified by the URL |
MOVE | Requests the server to move the specified page to another network location |
OPTIONS | Detect the request method supported by the server for the requested URL |
TRACE | The proxy server, firewall or gateway that the first request went through |
2. Request header
The request header consists of keywords + keyword values, separated directly by:, format: Name:value, the function of the request header is to inform the server of the relevant content of the request through the client, there is more than one header.
3. Blank lines
There will be a blank line after the request header, which uses carriage return and line feed characters to notify the server that the request header information will no longer appear in the following content.
4. Request entity
Really requested content
6.http response message
Format: starting line + response header + blank line + response entity
1.Start line
Also known as the status line, it is used for status information of the server in response to client requests, consisting of version number <version> + status code <status> + reason phrase <reason-phrase>
<Version>: Which version the server responds to in response to the client's request <status>: Status code, 200, 404, etc. <reason-phrase>: The response status code information is deep, reason phrase <headers> : A lot of response headers <entity-body>: Response body
2. Response header
Similar to the request message, there are usually several header fields after the start line. Each header field contains a name and a value. Format: name:value
Content-Type: test/html; charset=utf-8 Content-Length: 78
3. Blank lines
There is a blank line after the last response header information, informing the client that there is no header information.
4. Response body
The response entity is loaded with data to be returned to the client. The data can be text or binary.
7.HTTP status code
status code | illustrate |
---|---|
1XX | Informational status code, used to specify certain operations corresponding to the client |
2XX | Success status code, I requested a resource, and the resource is there, which means the request was successful. |
3XX | Redirect status code, sometimes returning a new address |
4XX | Client-side error, the resource you requested does not exist, or when you requested it, our resource denied you access and you did not have permission. |
5XX | Server error message. Initiate a request to the server, and the server finds that it needs to run a script to call the parsing library. This will happen if an error occurs during the call, or your script has an error, which may also cause this problem. |
Common status codes
status code | illustrate |
---|---|
200 | The server successfully returned the web page. This is the standard status code returned by a successful HTTP request. |
201 | Created is displayed after the uploaded file is successful. |
301 | Move permanently, a permanent redirect, will return a new address and tell us which new address the address you requested will be permanently moved to. |
302 | fonud, temporary redirection, temporarily placed somewhere, will use "location: new location" in the response message |
304 | not modified The resource has not been modified in any way. |
403 | forbidden request to deny |
404 | not found The requested resource does not exist |
405 | method not allowed The method you are using is not allowed or supported |
500 | internal server error: server internal error |
502 | Bod gateway, the proxy server receives a pseudo response from the upstream server. The upper layer server returns an incomprehensible message, so the proxy server will indicate an error. |
503 | serive unavailable, the service is temporarily unavailable |
8. Introduction to HTTP headers
Classification of headers: general headers, request headers, response headers, entity headers (specifically used to represent the internal type, length, encoding format, etc. of resources in entities), extended headers (non-standard headers, which can be created by programmers)
1. General header
• Connection: Define the options related to requests and responses between C/S. In http1.0, if he wants to use persistent connections, the options he sets are Connection: keep-alive,
• Cache-Control: Cache control to achieve more refined cache control. More common on http 1.1
2. Request header
• Client-IP: Client IP address
• Host: The requested host, this is useful when implementing hostname-based virtual hosting
• Referer: Indicates the URL of the original resource requested for the current resource. Using referer can prevent hot links.
• User-Agent: User agent, generally the browser
• Accept header: refers to which encoding types the client can accept
▪ Accept: the type of media that the server can send
▪ Accetp-Charset: received character set
▪ Accept-Encoding: encoding format
▪ Accept-Lanage: Acceptable language encoding format
• Conditional request header: (only used in http1.1)
When sending a request, first ask the other party whether the conditions are met. If the conditions are met, the request will be made. If the conditions are met, the request will not be made.
• Security related requests:
▪ Authorization
▪ Cookie
3. Response header
• Age: How long the resource can be used after it responds to you
• Server: Inform the client of the program name and version used.
• Negotiation class header:
▪ Vary: header list. The server will select the most suitable version based on this list and send it to the client.
• Security-related:
▪ WWW-Authentication
▪ Set-Cookie
4. Entity header
• Location: Indicates the new location of the resource, usually used when implementing the 302 response code.
• Allow: Request methods allowed for this resource
• Content-related headers
▪ Content-Encoding
▪ Content-Language
▪ Content-Length
▪ Content-Location: where the content is located
▪ Content-Type
• Cache related:
▪ ETag: extended tag/tag
▪ Expires: Expiration time
▪ Last-Modified: Last modified time
9. What are URLs and URIs?
• URI(Uniform Resource Identifier) same resource identifier
A string used to identify the name of an Internet resource. This identification allows your users to interact with the resource through a specific protocol. Every resource available on the Web, including HTML documents, images, video clips, programs, etc., is located by a universal resource identifier. So we can use URI to identify the name of each resource
• URL (Uniform Resource Locator) (Uniform Resource Locator)
Used to describe a specific location of a resource on a specific server.
For example: http://www.baidu.com:80/download/bash-4.3.1-1.rpm
The format of the URL is divided into three parts
i. scheme (also called protocol): http://
ii. Internet address: Generally this address refers to the server: www.baidu.com:8080
iii. Resources on a specific server: download/bash-4.3.1-1.rpm
10.What is CGI?
Common Gateway Interface Common Gateway Interface
When the web server finds that it needs to execute a script, it interacts with the back-end application through the CGI protocol and dynamically delivers the user's request to the server. The server's results are returned to the http server through the CGI protocol.