HTTP protocol Learning

Source: Internet
Author: User

First, what is the HTTP protocol protocol refers to the computer communication network in the communication between the two computers must abide by the provisions or rules, Hypertext Transfer Protocol (HTTP) is a communication protocol, which allows Hypertext Markup Language (HTML) documents to be transferred from the Web server to the client's browser. It can make the browser more efficient, reduce network transmission, not only ensure that the computer transfer hypertext documents correctly and quickly, but also determine which part of the transmission document, and which part of the content first display (such as text before the graphics), etc., is an application layer protocol, consisting of requests and responses. Second, the main features of the HTTP protocol 1, support client/server mode. 2, simple and fast: When a customer requests a service from the server, it simply transmits the request method and path. The request method commonly has, POST. Each method specifies a different type of contact between the customer and the server. 3, Flexible: HTTP allows the transfer of any type of data objects. The type being transmitted is marked by Content-type. 4, no connection: The meaning of no connection is to limit the processing of one request per connection. When the server finishes processing the customer's request and receives the customer's answer, the connection is disconnected. In this way, the transmission time can be saved. 5, stateless: HTTP protocol is a stateless protocol. Stateless means that the protocol has no memory capacity for transactional processing. A lack of state means that if the previous information is required for subsequent processing, it must be re-routed, which may cause the amount of data to be transferred per connection to increase. On the other hand, it responds faster when the server does not need the previous information. HTTP protocol workflow Once an HTTP operation is called a thing, the HTTP protocol works in four steps: Establish a connection, send a request message, send a response message, close the connection 1, first the client and the server need to establish a connection, just click on a super connection, the work of HTTP began; 2, After the connection is established, the client sends a request to the server in the form of a Uniform Resource Locator (URL), protocol version number, followed by MIME information including the request modifier, client information, and possible content; 3. After the server receives the request, it gives the corresponding response information in the form of a status line. Includes the protocol version number of the information, a successful or incorrect code, followed by MIME information including server information, entity information, and possible content, 4. The information returned by the client receiving server is displayed on the user's display by the browser, and then the client disconnects from the server. Iv. HTTP protocol-urlurl is a special type of URI that contains sufficient information to find a resource, typically http://< host >:< port >/< path; HTTP indicates that you want to locate network resources through the HTTP protocol,< host > represent a legitimate Internet host domain name or IP address;< endPort > Specify a port number, empty the default port 80;< path > Specifies the URI of the request resource, and if the URL does not give the < path, it must be given as a "/" in the request URI, which is usually done automatically by the working browser. Eg:1, Input: www.360buy.com browser automatically converted to: HTTP://WWW.360BUY.COM/2, http:127.0.0.1:8080/index.jsp Five, HTTP protocol- Request when the browser makes a request to the Web server, it passes a block of data to the server, that is, the request information, the HTTP request information consists of 3 parts: 1, the request line (Request way resource path HTTP version number) according to the HTTP standard, HTTP requests can use multiple request methods. HTTP1.1 supports 7 methods of request: GET, POST, HEAD, OPTIONS, PUT, delete, and Tarce. In Internet applications, the most common method is get and post. The difference between get and post methods: Get is generally used to get/query resource information, while post is typically used to update resource information 1), the Get method is the default HTTP request method, we use the Get method to submit the form data, but the form data submitted by the Get method is simply encoded, It is also sent to the Web server as part of the URL, so there is a security risk if you use the Get method to submit the form data. For example Http://127.0.0.1/login.jsp?Name=test&id=123456 from the URL request above, it is easy to identify the content submitted by the form. (? Content) Additionally, the amount of data submitted is not too large because the data submitted by the Get method is part of the URL request; 2), the Post method is an alternative to the Get method, which is primarily to submit form data to the Web server, especially large batches of data. The Post method overcomes some of the drawbacks of the Get method. When submitting form data through the Post method, the data is not sent as part of the URL request but as standard data to the Web server, which overcomes the drawback that the information in the Get method is not confidential and the amount of data is too small. Therefore, for security reasons and respect for user privacy, the Post method is usually used for form submission. 2. The request header request header contains many useful information about the client environment and the request body. For example, the request header can declare the language used by the browser, the length of the request body, and so on. Accept: Used to tell the server that the client supports the data type Accept-charset: Used to tell the server, the Code table accept-encoding used by the client: to tell the server, the client supports the data compression format accept-language: Used to tell the server, the client's syntax environment host: Used to tell the server, The client wants to access the server host If-modified-since: Used to tell the server, the client's last cache time for the resource referer: used to tell the server, which page the client is from to access the server (anti-theft chain) User-agent: Used to tell the server, The machine environment of the client (for example, the operating system used, browser version number) Cookie: The client through this header field, can bring some data to the server connection: the client through this header field to tell the server, after the request is completed, is to keep the link or close the link 3, The message body (request body) is a blank line between the request header and the request body, which indicates that the request header has ended, followed by the request body. The request body can contain query string information submitted by the customer. The HTTP protocol-Response (response) HTTP response is similar to an HTTP request, and the HTTP response is made up of 3 parts, namely: 1, Response Line (Protocol status version Code description) Protocol status code describes the first line of the HTTP response similar to the first line of the HTTP request, It indicates that the protocol used to communicate is that the HTTP1.1 server has processed the requests made by the client. 2, the response header (Response header) Response header (Response header) also contains many useful information, such as server type, datetime, content type and length, as well as the request header. Location: This header is usually used in conjunction with the 302 status code, the server uses this header to tell the browser who to look for server: The server through this header tells the browser, the type of server content-encoding: The server through this header tells the browser, Data compression format (gzip) Content-length: The server tells the browser through this header, the length of the loopback data content-language: The language type of the content, for example: Zh-cncontent-type: The server tells the browser through this header, Type of loopback data last-modified: The server tells the browser through this header, the last modification time of the data refresh: The server tells the browser through this header, how long time to refresh the content-disposition: Controls the browser to open the loopback data transfer-encoding: The server tells the browser through this header that the data is a block-back expires: The time to control the browser's cache data (-1 or 0, which represents the control browserDo not cache) Cache-control:no-cachepragma:no-cache more than three heads together, you can control all browsers do not cache data 3, the body of the message (response body) response body is the HTML page returned by the server, The response header and the body must also be separated by a blank line. * Response Status Code: The HTTP status code reflects the status of the Web server processing HTTP requests. The HTTP status code is made up of 3 digits, where the first number defines the type of the status code: the 1xx-Information Class (information), which indicates that a Web browser request is being received, the 2xx-Success Class (successful) is being further processed, indicating that the user request was received correctly, Understanding and Handling For example: the ok3xx-redirect Class (redirection) indicates that the request was unsuccessful and the customer must take further action. 4xx-Client error, which indicates that the client submitted a request with an error, for example: 404 NOTFound, means that the document referenced in the request does not exist. 5xx-Server error indicates that the server was unable to complete the processing of the request: 500

  

HTTP protocol Learning

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.