http and HTTPS
HTTP protocol (Hypertext Transfer Protocol, Hypertext Transfer Protocol): is a way to publish and receive HTML pages.
- The port number for HTTP is 80
HTTPS (hypertext Transfer Protocol over secure Socket layer) is simply the secure version of HTTP, which is added to the SSL layer under HTTP.
- SSL (Secure Sockets layer) is mainly used for the secure transport Protocol of the Web, which encrypts the network connection at the transport layer and guarantees the security of data transmission on the Internet.
- The port number for HTTPS is 443
How HTTP Works
The main function of a browser is to make a request to the server to display the network resources you choose in a browser window, which is a set of rules for computers to communicate over the network.
HTTP requests and Responses
HTTP communication consists of two parts: a client request message and a server response message
the process by which the browser sends an HTTP request:
1. When the user enters a URL in the address bar of the browser and presses the ENTER key, the browser sends an HTTP request to the HTTP server. HTTP requests are mainly divided into "Get" and "Post" methods.
2, when we enter the URL http://www.baidu.com in the browser, the browser sends a request to get the http://www.baidu.com HTML file , the server The response file object is sent back to the browser.
3, the browser analysis response in the HTML, found that it refers to a lot of other files, such as images files, CSS files, JS files. The browser will automatically send the request again to get a picture, CSS file, or JS file .
4, when all the files are downloaded successfully, the Web page will be based on the HTML syntax structure , the complete display.
URL(abbreviation for uniform/universal Resource locator):
A Uniform Resource locator is an identifying method that is used to describe the addresses of web pages and other resources on the Internet in a complete manner.
Basic format:scheme://host[:port#]/path/…/[?query-string][#anchor]
- Scheme: Protocol (for example: HTTP, HTTPS, FTP)
- Host: The IP address or domain name of the server
- port#: Port of the server (default port 80 If you are going to the protocol defaults)
- Path: access to Resource paths
- Query-string: parameter, data sent to HTTP server (GET request)
- Anchor: Anchor (jumps to the specified anchor position of the Web page)
For example:
One, the client HTTP request
The URL simply identifies the location of the resource, and HTTP is used to commit and fetch the resource. The client sends an HTTP request to the server's request message, including the following format:
请求行 , 请求头部 , 空行 , 请求数据
Four parts, the general format of the request message is given.
A typical example of an HTTP request
Request method (first written in the request line)
HTTP requests are mainly divided into Get Post two ways
-
Get is the data that is fetched from the server and post is the data sent to the server
-
The GET request parameter is displayed on the browser URL, and the HTTP server generates the response based on the parameters in the URL that the request contains, that is, the parameters of the "Get" request are part of the URL. For example:http://www.baidu.com/s?wd=Chinese
-
Post request parameters in the request body, the message length is not limited and implicitly sent, usually used to submit to the HTTP Server a large amount of data (such as the request contains many parameters or file upload operations, etc.), the requested parameters are included in the "Content-type" message header, Indicates the media type and encoding of the message body,
Common Request Headerssecond, the service side HTTP response
The HTTP response is also made up of four parts, namely: 状态行 , 消息报头 空行 响应正文 ,,
Common response Headers (learn)
In theory, all response header information should be in response to the request header. But for the sake of efficiency, security, and other considerations, the corresponding response header information is added, which can be seen from:
Response Status Code
The response status code consists of three digits, and the first number defines the category of the response, and there are five possible values.
Common Status Codes:
- 200: The request was successful.
- 302: Request redirection.
- 304: The request resource has not changed to access the local cache.
- 404: The request resource does not exist. This is usually a user path write error, or the server resource has been deleted.
- 500: Server internal error. Usually the program throws an exception.
304 Status Code reason
cookies and Session:
The interaction between the server and the client is limited to the request/response process and is disconnected after the end, and the server will consider the new client on the next request.
In order to maintain a link between them, let the server know that this is a request sent by a previous user, you must save the client's information in one place.
Cookie: Determines the user's identity by the information recorded on the client.
Session: Determines the user's identity by information logged on the server side.
HTTP and HTTPS