HTTP Learning Note (2) HTTP messages

Source: Internet
Author: User

1, what is an HTTP message?

In the previous section we learned that data is being transmitted between the browser and the server, which is called the message flow, and the flow of the stream flows into and out of the streams, and of course there are upstream and downstream, all of which are to determine the flow of the message.

The flow of messages is downward, not reflux, such as:

2, the composition of the message

Intuitive look at the composition of a message.

Request message:

Response message:

(1) Format of request message:

<method> <request-URL> <version>--Start line request Line <entity-body>--Main body

(a) starting line:

Method: The starting line of the request starts with a method that tells the server what to do.

For example, the first word in the request message post, in fact, it is a method, its meaning is to send the server to deal with the data.

Request-url: The request URL describes which resource to perform the action on. For example, this part of the request message above.

version: The request line also contains versions of HTTP to tell the server what kind of HTTP the client is using.

(b) Header:

The HTTP header field adds some additional information to the request message. Essentially, they are just a list of some name/value pairs.

Common header:

(c) Main body:

The third part of the HTTP message is the optional entity body part. The body of the entity is the payload of the HTTP message. is what HTTP is about to transfer.

(2) format of the response message:

<version> <status> <reason-phrase>--Start line response line

<entity-body>

Note The format of the response message is only the first part of the different, that is, the request message request line and Response message response line content format, the remaining format is the same.

Response Line: The first version is the HTTP version used by the response, the second status is the number status code, and the third is the reason phrase reason-phrase

3, focus on carding

From the above analysis, we can see that the message is nothing more than that, starting line (containing the request line and Response line): The request line contains a method, it tells the server what to do, of course, the next is the specific location of the resources to operate, followed by the version number. The response line contains a version followed by a status code and a reason phrase.

Method Summary:

(1) The Get method usually requests that the server send a resource to the requester.

(2) The head method is similar to the Get method, and the request server returns something, but the difference is that the head method does not return the entity part, which means that there is no real access to the server's resources, but its role is:

To understand resources without acquiring resources (for example, to determine their type);
? See if an object exists by looking at the status code in the response;
? Test whether the resource has been modified by looking at the header.

(3) The Put method writes a resource to the server. The semantics of the Put method is to have the server use the principal part of the request to create a new document named by the requested URL, or, if that URL already exists, to replace it with that subject.

(4) The Post method sends data to the server, and the server determines what value is returned based on that data. The common application of this work is to access other people's WebService interface, such as a text interface, you just enter the phone number will return the call log.

(5) The Delete method, of course, removes the resource from a location on the server, but the client application cannot guarantee that the delete operation will be performed. Because the HTTP specification allows the server to revoke a request without notifying the client.

In fact, there are other methods, not introduced, but one thing to note is that there is a noun called security method, in fact, is to see which methods have an impact on the server, such as Get and head is certainly safe, but the request will not be modified, but the Delete method is not necessarily, Therefore, the Delete method is not a security method.

As for the status code, do not have to deliberately remember, check the documentation can be. Some of the above images are from the HTTP authoritative guide.

HTTP Learning Note (2) HTTP messages

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.