HTTP Protocol (iii) several data transmission modes

Source: Internet
Author: User

Talk about some of the features of the HTTP protocol:

1) No Status

The HTTP protocol is a protocol that does not save the state of communication between the request and the response itself, that is, the stateless protocol.

The advantage of this setting is that it processes more request transactions faster and ensures the scalability of the Protocol

However, with the continuous development of the web, sometimes it is necessary to maintain this state, and then introduced the cookie technology, cookie technology through the request and response messages to write cookie information to control the state of the client.

We'll talk about the contents of the cookie later ...

2) Durability

Normally when you send HTTP, you need to establish a TCP connection, and then send the paper.

If you need to go through this process every time you want to send an HTTP message, most of the time is consumed in the process of establishing and disconnecting the connection.

Therefore, the Connection property is used in HTTP to specify how the connection should be made.

When set to Keep-alive,http, a persistent connection is established, and there is no need to establish a connection every time and then interrupt.

The advantage of this is that the server side of the load, reduce the cost of the part of the time, so that the HTTP request and response to the end of the faster, the corresponding, the Web page display speed is relatively improved.

3) Pipeline

If an HTTP request requests a large number of images and other large files, what about the other HTTP requests?

Now, the advent of pipeline technology makes HTTP requests faster than persistent connections, characterized in that the more requests, the more obvious the time difference.

4) Content encoding

Because of the content of some messages is too large, so in the transmission, in order to reduce the time of transmission, will take some compression measures.

For example, in the message information above, accept-encoding defines the format of the content encoding: gzip

There are several ways:

GZIP:GNU compression format

Standard compression format for Compress:unix systems

Deflate: is a lossless compression format that uses both LZ77 and Havermann encoding

Identity: Do not compress

5) Multi-part object collection

Sometimes the content of the transmission, not just some strings, but also some pictures, characters, music binary and other mixed content.

This requires the use of a multi-part object collection, multipart, such as the code for writing a Web upload file in Java, which needs to specify the form's encoding format in the form.

Set the value of the Enctype property of the form to Multipart/form-data.

This is because by default the format used by the form is: applicatin/x-www-form-urlencoded, this encoding format will encode all the content, not suitable for uploading the file this case.

The differences between the two encoding formats are mainly:

The multipart/form-data will encode the contents of the form with the control as its benchmark.

Application/x-www-form-urlencoded will encode the contents of the form into a key-value pair.

6) Scope request

In some scenarios, HTTP messages request some very large images, but the loading process is slow.

For example, we log in some large images of the URL, we will find that sometimes the picture is a piece of loading.

This is because the length of the HTTP request is set so that the resource file can be loaded in chunks.

Using the Range property in the request message, you can specify a byte range of HTTP requests using the Content-type attribute in the response message.

Next, talk about several kinds of HTTP protocol data transfer methods

There are many ways to transmit the HTTP protocol, security considerations, commonly used are get and post two kinds, first to introduce the following two

1) Get: Get Resources

The Get method is used to request access to a resource that has been identified by the URL

2) POST: Transfer entity body

The Post method is used to request that the server transport the body of the information entity

The difference between get and post:

First, the use of the target is different: The Get method is only used to query, does not affect the information on the browser, each get method is the same

Second, the size is different: Get is placed in the URL header, so the size as the browser, and post is in the message, as long as there is no specific restrictions, the size of the file is unlimited

Then, the security is different: Get is in clear text transmission, and post is placed inside the message, cannot see

From the perspective of the use of the scene, generally like user registration login This information is private, the use of post, and for queries, etc., in order to fast, mostly using get transmission.

(about the difference between get and post, recently re-read a lot of other people wrote blog Ah data, found that the above explanation is vague, I will be in the comment area below the difference clearly described, of course, the following blog will be explained in detail)

Next, we introduce several other data transfer methods:

3) PUT: Transfer file

Put requires that the contents of the file be included in the body of the request message, and then saved to the location specified by the request URL

For security reasons, the general Web site does not use this method, and it may be open for use with web-based security validation mechanisms, or if the architecture uses a restful web site.

4) HEAD: Get message header

Head and get method, just do not return the text body part, to confirm the validity of the URI and resource update date and time, etc.

5) Delete: Delete file

Delete is the opposite of put, which deletes the specified resource by request URI

For security reasons, the general Web site does not use this method, and it may be open for use with web-based security validation mechanisms, or if the architecture uses a restful web site.

6) Opyions: Ask for support methods

Method used to query for resource support specified for the request URI

7) Trace: Trace Path

is a way for the Web server to return the previous request communication back to the client

When sending the request, fill in the number in the Max-frowards header field, each pass a server side 1, when the value is 0 o'clock, stop the transmission, and finally receive the response of the server return status code OK

However, this method is rarely used, and it is easy to cause xst (cross-site tracking) attacks, it is not used.

8) Connect: Requires Tunneling Protocol connection Agent

This method requires that the tunnel be established in the Proxy server communication, the TCP communication is implemented by the tunneling Protocol, and the communication content is transmitted through the network mainly using SSL (Secure Sockets Layer) and TLS (Transport Layer Security) protocol.

Finally, attach a http1.1 and http1.0 version of the respective supported methods, in addition, pay attention to capitalize ...

Among them, link and unlink have been HTTP1.1 abandoned, no longer support!

HTTP Protocol (iii) several data transmission modes

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.