HTTP protocol Learning

Source: Internet
Author: User

First, the URL

In the HTTP transmission, we all look for the network resources through the URL. But do you really know the URL? Do you know what is the composition of the URL? If you know, well, congratulations, you can skip the URL section. oh~~ if not, please come with me to meet the URL we have to knock hundreds of times a day! First say the composition of the URL (Uniform Resource Locator). The URL is made up of three parts, Transport protocol + domain name or IP address + port (defect 80) + resource-specific address . If you want to specify an access port, use the :"To separate for example (http://www.baidu.com:80/index.php). For example: http://www.baidu.com/index.php (Transport protocol is HTTP, domain name or IP is www.baidu.com, resource specific address is index.php). In general, the browser has done a lot of things for us, such as the previous transport protocol, without specifying a specific resource path, the default plus "/" to indicate the request of the default resource (index.php in the example). So by default, when you type www.baidu.com, the browser automatically adds "http:/" and "/" to the end.

II. Resource requests (request)

First, what do we want the target host to send when we request a URL? This is very simple, we need only through the browser developer tools to see, the following we will visit Baidu (www.baidu.com) as an example, to see when we request a URL, the client to the server sent those things? What about the request message structure?(Thanks to share's friends, let me save the time of my own drawing ^_^): The message composition structure of request is such three parts,The first part is the first line on the graph, called the Requestline (request line) Map of the Method/path row. The second part is the area of the Requestheader (request header) corresponding to the header-name-1 in the diagram. The third part is the request content, the optional request body portion of the way. In the first line, method indicates the request method, common such as:
GET: Request a resource from a Web server post: Send a resource to the Web server put: Send a resource to the Web server and store it on the server delete: Delete a resource from the Web server

When the request mode is get, the body part of the request is empty at this time it is possible to follow the parameters in the URL, at this time. The parameters will be in the Requestheader area. In the Path-to-resource section is the request resource name, such as the URL (www.baidu.com/index.php) then Path-to-resource will be replaced by index.php, the last http/ Version-number represents the protocol type and version that the request uses.in Requestline, we declare our request method, request resource (Path-to-resource) and protocol type and version (Http/version-number) to the server;Requestheader There are many parameters, such as, we visit the Baidu Home page (www.baidu.com) Request information: From the above requests we can be informed, I ask is to use get the way to request www.baidu.com ( The default resources on port 80), the request protocol is HTTP, the version is 1.1, the state is a long connection, and tells the server we can receive the resolution gzip, deflate, sdch three compression methods of data, we receive the language is ZH-CN, And we request that we carry the cookie information. Let's look at what these commonly used parameters mean and what they do.
Host: Represents the Request server address (domain/IP).

Connection: Indicates whether a persistent connection is required, at HTTP 1.1, the default is a long connection, that is, the connection is in the KeepAlive state, the advantage is that the resource contains more than one element (such as a picture in a Web page) will reduce the download time, When connection is keep-alive, it means that the connection is not disconnected during the keep-alive time. Instead of KeepAlive mode, the request will be disconnected.

Accept: Specifies the types of content that the client can accept, the order in which the clients are accepted, as in Accept:text/xml,application/xml,application/xhtml+xml, text/html;q=0.9,text/plain;q=0.8.

user-agent: Represents the client browser details of the request, through which the server can determine the current client port browser category.

DNT:D an abbreviation for the O not track, requiring the server not to log user information. When 1 is on, 0 indicates off. These are supported by mainstream browsers, and in Chrome,firefox you can find this setting in Settings.

accept-encoding: The browser can handle the encoding, non-character encoding but refers to the resource compression method (whether compression, support that type of compression gzip,deflate, etc.).

accept-language: The client declares that it can receive languages such as gb2312 Utf-8, language and character sets, and that the language contains characters.

Cookies: When a browser requests cookie information for a resource that is requested by the server at the time of request, the cookie will be Help server to identify whether it is a historical visitor (please remember my function is implemented in this way.) Writes the user's information back to the client's cookie when respoonse. When the user visits the second time to first check whether the visitor has carried a valid cookie to do different UI rendering or no login, the cookie content is self-signed by the server program, the primary format is name (cookie name), value (the name corresponding to the cookie) [ Name-value stores the],domain (domain name address) in the form of a key-value pair, path (resource path, which controls the effective access range of the cookie), Max-age (valid, in seconds, and expires after this time.) )。 That's right. In fact, the session is also stored through cookies. Only a cookie stores a seesionid when the session is stored. The session is actually stored in the server process.

more specific This article will not be elaborated, please refer to this address to check Request Header parameter check the address or this .

Summary: The method is to tell the server what needs to be done.

It is noteworthy that the flow of the message is always downstream (at the request point as the starting point, want to flow downstream, if the client initiated the request is the request message flow is [client, Agent 1, agent 2., Server], the response message is instead. )  Third, server response (Response)when we make a request, the requested server will definitely give us something back (assuming a connection to the server)? What is the return? If the request succeeds, the result of our request is returned, the request fails with an error message, the processing state of the request, and so on. The client is the state of the request returned by the server to determine the result of the request, so we must first understand the state of the response when requesting a response.

The response status code is used to represent the different processing results and status of the server to the request, and he is a three-dimensional decimal number. The response status code can be categorized as 5 , using the highest bits of 1 to 5 to classify, as follows:

(1)100-199: Indicates a successful receive request that requires the client to continue submitting the next request in order to complete the process.

(2)200-299: Indicates a successful receipt of the request and completes the entire processing process.

(3)300-399: If the requestis not completed, the customer needs to further refine the request, for example, the requested resource has been moved to a new address.
(4)400-499: Client request error.
(5)500-599: Error occurred on the server.

For status values, click here for an official explanation.

Again, let's take a look at the protocol header structure, like, and the request is the same. The same three parts.

The first part is the first line on the graph, called the Responseline (request line) Map of the Method/path row. The second part is the area of the Responsetheader (request header) corresponding to the header-name-1 in the diagram. The third part is the request content, the optional request body portion of the way.

The Http/version-number is the protocol version and Status code is the one described above. A message is a return status message.

Also to visit Baidu homepage For example, we get the response information such as

As you can see from the diagram, the www.baidu.com we requested responds with a status code: "$" is: OK. The response content (content-type corresponding value) is of type "text/html;" Encoding method is Utf-8, the response class capacity encoding (content-encoding) Transmission encoding method (non-character encoding method but compression mode such as chunked, deflate, gzip) is chunked. and write-back cookie information. The meaning and explanation of the various entity objects please poke here and don't repeat them. I'll elaborate on the role of status codes and entity objects in subsequent posts. Summarize this blog post:First we have a new understanding of the URL, its composition and structure. Second, we looked at what we were telling and carrying that information to the server when we visited a resource. and request structure composition and content. In the end we explore, in turn, what information, and the structure and content of response, the server has sent back to us after our request was answered. In the next article we will delve into status code--state code. And what each different status code corresponds to, what the status code does to our developers and what it means. Finally, a comparison of the request message and response message is updated with the image from the HTTP authoritative guide and the composition of the message:

interested can poke → → → web_sniffer-------Here you can enter a valid domain name. will be able to see the information of request and response very clearly.

Reference: Http://blog.163.com/ny_lonely/blog/static/1889242732013101825444500/Series article http://www.cnblogs.com/ok-lanyan/ Archive/2012/07/14/2591204.html http://blog.csdn.net/zhll3377/article/details/7748086

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.