The WEB must know -- the illustration Http (on), the web must know

Source: Internet
Author: User
Tags http cookie

The WEB must know -- the illustration Http (on), the web must know

This article summarizes the relevant knowledge about http. The main content of this article is as follows:

The main explanations include:

1. The difference between a URL and a URI.

2. The request message and the content of the corresponding message.

3. Difference Between GET and POST.

4. http cookie, persistence, pipeline, multi-part object set, and range request.

Other http-related knowledge will be updated later.

Keywords

The URL is a string address that we access the web. What is the URI? What are their relationships?

Let's take a look at the official explanation:

URL: uniform resource location unified resource Locator

URI: uniform resource identifier

This means that the URI is a resource identifier, and the URL is also a URI and a resource identifier, but it also specifies how to Locate the Locate to this resource.

URI is an abstract resource identifier, which can be absolute or relative. However, a URL is a URI that specifies the location information and must be absolute.

What we usually call relative addresses is just relative to another absolute address.

 

RFC: reqeust for comments for amendment comments

RFC is known as the network knowledge Bible, which defines the basic content of protocols in the network. Therefore, applications in different systems can access each other.

Message format

First, the message format is as follows:

The blank line is used to distinguish the first part of the message and the body content of the message. It is composed of a carriage return and a linefeed.

Both request packets and response packets require a header. Of course, some request packets of the message body do not exist.

Generally, the request message format is as follows:

The request header contains other content, which is not listed in detail.

The Response Message format is as follows:

Next, let's take a look at the content of http packets in different browsers:

Is the http Content in chrome, where request headers describes the content of the request packet header and response headers describes the content of the response packet header.

The longest used attribute is:

1 URL, that is, the http access address

2 request method: The request method of the message

3 status code, status code, and status phrase

4 Accept Encoding, Content Encoding

5 Connection

6. Cookie: added cookie content

7 Host: Target Host

8 User-Agent: client browser Information

9 Set-Cookie: specifies the content to be saved in the Cookie

The common attribute content is the above.

The Display Methods captured in IE are different, but the content is the same:

Http Request Method

There are many methods to send http, but the most common ones are POST and GET.

For other reasons, we do not recommend this feature. So what is the difference between POST and GET?

1. Different use targets:

Both POST and GET are used to obtain information, but the GET method is only a query, and does not have any effect on the content on the server; the content of each GET is the same.

POST is often used to send certain content for some modification operations.

2 different sizes:

Because different browsers have certain character restrictions on the length and size of the URL, the GET method is placed in the first part of the URL, but the specific size depends on the browser.

The POST method places the content in the message content, so as long as there is no limit on the content of the message, there is no limit on its size.

3. Different security:

As mentioned above, GET is directly added to the end of the URL, and the content can be seen directly in the URL.

The POST is placed inside the message and cannot be seen directly by the user.

In general, GET is used to GET a certain content, and POST is used to submit a certain data request.

Generally, the user-registered content is private in use cases, and the POST method should be used. For a specific content query, you can use the GET Method for fast response.

  

Stateless

Http is a stateless protocol, so no http information is recorded on the client or server.

This design reduces the load on the server and the overhead of http requests.

But in some special scenarios, we need to record user information at all times. What should we do?

Cookie can solve this problem. The Cookie operating mechanism is as follows:

Cookie is the content that is determined by the server and saved in the browser of the client. In this way, you do not need to add user-related information every time. The request will automatically add the corresponding content in the cookie.

Persistence

Normally, when sending http, you must establish a TCP connection and then send packets.

If you want to send an http message every time, this process consumes most of the time during the process of establishing and disconnecting.

Therefore, the connection attribute is used in http to specify the connection method.

When it is set to keep-alive, as shown in the http header information of www.baidu.com shown above, a persistent connection is established.

You do not need to establish a connection every time before interruption.

Pipeline

What if an http request requests a large number of images and other large files?

Don't be afraid. http can send multiple http requests at a time and wait for the response to connect. There is no need to wait in line, which speeds up the http response time.

Content Encoding

Due to the large content of some packets, some compression measures are taken to reduce the transmission time during transmission.

For example, in the preceding message, Accept-Encoding defines the content Encoding format: gzip

There are several methods:

Gzip: GNU compression format

Compress: Standard compression format for UNIX systems

Deflate: a lossless compression format that uses both LZ77 and hafman encoding.

Identity: Do not compress

 

Multi-part object set

Sometimes, the transmitted content is not only strings, but may also contain a mixture of pictures, characters, and binary music.

This requires a collection of multiple objects and multiparts. For example, when writing code for a web file to be uploaded using java, you must specify the form encoding format in form.

Set the value of the enctype attribute of form to multipart/form-data.

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

The differences between the two encoding formats are as follows:

Multipart/form-data encodes the content in the form based on the control.

Application/x-www-form-urlencoded encodes the content in form into a key-value pair.

Range request

In some scenarios, http packets request large images, but the loading process is slow.

For example, if we log on to the URLs of some big images, we will find that sometimes the images are loaded in one piece.

This is because the length of the http request is set, so that resource files can be loaded in parts.

Use the Range attribute in the request message, and use the Content-Type attribute in the Response Message to specify http requests with a certain byte Range.

Reference

[1] The difference between URL and URI: http://www.cnblogs.com/gaojing/archive/2012/02/04/2413626.html

[2] The difference between POST and GET: http://www.cnblogs.com/hyddd/archive/2009/03/31/1426026.html

[3] GET and POST length limit: http://blog.csdn.net/blueling51/article/details/6935901

Author: xingoo
Github: https://github.com/xinghalo
The copyright of this article is shared by the author and the blog Park. You are welcome to repost this article. However, you must retain this statement without the author's consent and provide a clear link to the original article on the article page. Otherwise, you will be held legally liable. Category: JavaScript

Related Article

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.