Basic knowledge of the HTTP protocol, including request flow, request method, etc.

Source: Internet
Author: User
Tags rfc

What is the HTTP protocol?

  HTTP is an abbreviation for the Hyper Text Transfer Protocol (Hypertext Transfer Protocol). Its development was the result of collaboration between the World Wide Web Association (Wide) and the Internet Working Group IETF (Internet Engineering Task Force), which eventually released a series of RFC,RFC 1945 defines the http/1.0 version. The most notable of these is RFC 2616. RFC 2616 defines a version of--http 1.1 that is commonly used today.

Hypertext Transfer Protocol is a rule that specifies the communication between the browser and the World Wide Web server, and transmits the data transfer Protocol of the World Wide Web document over the Internet.

The HTTP protocol (hypertext Transfer Protocol, Hypertext Transfer Protocol) is the transfer protocol used to transfer the text from the WWW server to the local browser. It can make the browser more efficient and reduce the network transmission. It not only ensures that the computer transmits hypertext documents correctly and quickly, but also determines which part of the document is being transmitted, and which content is displayed first (such as text before graphics), and so on.

HTTP is an application-layer protocol that consists of requests and responses and is a standard client server model. HTTP is a stateless protocol.

HTTP protocol Features

  The main features of the HTTP protocol can be summarized as follows:

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. Because the HTTP protocol is simple, the HTTP server's program size is small, so the communication speed is fast.

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.

Methods for HTTP requests:The http/1.1 protocol defines eight methods (sometimes called "actions") to indicate how the Request-url specified resources operate differently. 1. OPTIONSreturns the HTTP request method that the server supports for a specific resource, or a request to send a ' * ' to the Web server to test the server's functionality2. HEADa response that matches a GET request to the server, except that the response body will not be returned. This method can get the meta information contained in the response small message header without having to transmit the entire response content. 3. GETmake a request to a specific resource. It is essentially sending a request to get a resource on the server. Resources are returned to the client through a set of HTTP headers and rendering data (such as HTML text, or pictures or videos). In a GET request, the rendering data is never included. 4. POSTsubmits data to the specified resource for processing requests (such as submitting a form or uploading a file). The data is included in the request body. A POST request may result in the creation of new resources and/or modification of existing resources. Corresponding POST request function in LoadRunner: Web_submit_data,web_submit_form5. PUTupload the latest content to the specified resource location6. DELETErequesting the server to delete the resource identified by Request-url7. TRACEEcho the request received by the server, primarily for testing or diagnostics8. CONNECTThe http/1.1 protocol is reserved for proxy servers that can change connections to pipelines. Note:1) The method name is case-sensitive, and the server should return a status code of 405 (Mothod not allowed) when a request is directed to a resource that does not support the corresponding request method, and the status Code 501 (not) should be returned when the server does not recognize or support the corresponding request method. Implemented). 2) The HTTP server should at least implement the Get and Head/post methods, the other methods are optional, and in addition to the methods described above, a specific HTTP server supports extending the custom method.

Get and post differences

Difference:

Get request no message body, can carry only a small amount of data

The POST request has a message body that can carry large amounts of data

How to carry Data:

Get request to put data in URL address

The POST request places the data in the body of the message

The GET request submits the data to be placed in the HTTP request protocol header, and the data submitted by the post is placed in the Entity data;
The Get method submits only 1024 bytes of data, while Post does not have this limit.

HTTP protocol Request Flow

1. Open the HTTP connection. Be sure to remember that HTTP is a stateless protocol. Because of this, you have to create a new connection for each request.

2. Set the HTTP request header. Here the bread contains the type of data to be transmitted (binary) and the total length of the data.

3. Send the request. Writes a binary stream to the server.

4. Read the request. The target servlet program is called and accepts HTTP request data. The servlet program selects the appropriate method for invoking all the necessary parameters. Note that if this is the first request from this client, a new instance of the server object will be created.

5. Call the method. Method will be called by the server-side object.

6. Initialize the method response. If the calling method throws an exception, the customer receives an error message. Otherwise, the returned type (if any) will be sent.

7. Set the HTTP response header. In the response header, you must set the type and length of the data to be sent.

8. Send the response. The binary data stream is sent from the Web server and returned to the client.

Basic knowledge of the HTTP protocol, including request flow, request method, etc.

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.