HTTP Request Process Overview

Source: Internet
Author: User

Http://www.cnblogs.com/stg609/archive/2008/07/06/1236966.html

Http://www.longen.org/E-K/detaile-k/HttpRequestIntroduction.htm

Http://stblog.baidu-tech.com /? P = 1148

Http://www.cnblogs.com/zhangleong/archive/2011/04/02/2003003.html

Http://fred.easymorse.com /? P = 40

 

I have been studying how to enable Asp.net to upload large files recently, so I have no technical skills.Article. Unfortunately, I haven't studied it yet ~~~. However, I also learned about the general process of HTTP message requests. I will briefly introduce how to use Telnet to simulate HTTP requests. I hope you can tell me something wrong. Because the content is large, it is divided into two parts for writing.
1. Process Overview
2. telnet to simulate HTTP requests

This is a brief introduction.
First ask a question: when we enter "http://www.baidu.com/" in the address bar of the browser, and then press "enter", what happened after that? I will not answer the question here. Let's look at it first.

Let's analyze:

·HTTP Request Process

First, HTTP belongs to the application layer protocol in the TCP/IP model, and the two applicationsProgram(We mean the browser and the server) need to communicate with each other. First, you must establish a TCP connection before the browser can send request information to the server. After the server receives the request information, return the corresponding response information. After receiving the response information from the server, the browser interprets and executes the data.

In HTTP 1.0, Each browser request (that is, access to each page) requires a separate connection. After each request is processed, the connection is automatically released. (We should all feel this. For example, when we access a page and the page is displayed in a browser, We can unplug the network cable, at this time, the information on this page will not be lost .) When the requested webpage file contains many images, music, movies, and other information, the information returned by the server does not directly contain image data, but simply stores the link of the image, when the browser explains the image URL, it sends a request to the server for the image. It can be seen that if a webpage contains multiple image data, it will frequently establish connections with the server and release connections, which will undoubtedly cause a waste of resources.

HTTP 1.0 request Mode

HTTP 1.1 can process multiple requests in a connection, and multiple requests can overlap, without waiting for a request to end before sending the next request.

· HTTP Request Message

A complete HTTP request message includes one request line, several message headers, and entity content. The message header and entity content can be absent, and there is a blank line between the message header and entity content.
Let's look at an example (I added the serial number before each row for ease of illustration ):
1 get/mattmarg/HTTP/1.0
2 User-Agent: Mozilla/2.0 (Macintosh; I; PPC)
3 accept: text/html ;*/*
4 COOKIE: name = Value
5 Referer: http://www.XXX.com/a.html
Among them, the second row is the request line: the request method is get (in addition to get, there are post, put, delete), the requested file is located under the "root directory/mattmarg, of course, you can also directly provide the required page (for example,/mattmarg/index. ASP, you can also add some other fields such as/mattmarg/index. asp? Id = 1 & uid = xxx. When we use a GET request, the length of the request line submitted to the server cannot exceed 1 K. If we use the POST method, the submitted information is sent to the server in the form of entity content, therefore, if there is no limit on the server, in principle, infinite content can be transmitted.) HTTP/1.0 indicates that the HTTP Version is 1.0. The remaining lines are the message header, which is mainly used to send certain information or instructions to the server. For example, tell the server what the User-Agent is (if the browser is used, the corresponding browser model is returned) and what the terminal can interpret as the type (accept, the page from which the request is submitted (Referer), and the language that the browser can interpret (accept-language. Here we take accept-language as an example. We all know that Google displays Simplified Chinese in mainland China, while other countries display the corresponding language. How does this happen? In fact, the request information submitted by the browser to the server contains the accept-language, while our browser uses ZH-CN by default, and the server returns the corresponding page when receiving the information.
We can verify it using the following methods:
1. Open the browser-> Tools-> Internet Options-> General Tab 2. Select "language". The default language is Chinese. 3. Select "add" and select a language, then adjust the priority order. 4. After confirming the rule, visit http://www.google.com/. this means that the original Simplified Chinese language has become a traditional Chinese character.

· HTTP Response Message

The format of an HTTP response message is: a status line, several message headers, and entity content. The message header and entity content can be absent, and there is a blank line between the message header and entity content.
Let's look at an example:
01 HTTP/1.1 200 OK
02 server: Microsoft-IIS/5.1
03 x-powered-by: ASP. NET
04 Date: Sun, 06 Jul 2008 11:01:21 GMT
05 Content-Type: text/html
06 accept-ranges: bytes
07 last-modified: Wed, 02 Jul 2008 01:01:26 GMT
08 etag: "0f71527dfdbc81: Ade"
09 Content-Length: 46
10
11 <HTML> Row 01 is the status line used to display the server response status. HTTP/1.1 shows the corresponding HTTP Protocol version, and 200 is the status number, OK is the status information used to explain the status Number (here OK corresponds to 200, indicating that the request is normal); 02 ~ 09 is the header of the message, 10 is empty rows, and 11 is the entity content (that is, the webpage content returned by the server ).

Well, I believe you have a rough understanding of the HTTP request process. Then, we will answer the questions we left at the beginning:When we enter"Http://www.baidu.com/", Then press" enter ". What happened after that?.

First, the browser finds the IP address pointed to by the URL, establishes a TCP connection with it, and then sends a GET request to the Baidu server. After the server receives our request, send us a Response Message-Baidu's page, and then disconnect.

[Supplement] the above article mainly describes the general process of HTTP requests. As for a series of connections established before HTTP, only "the browser finds the IP address pointed to by this website, then, it is included in the statement "or similar words to establish a TCP connection. According to replies from friends, this statement is not appropriate. So I will add something here.
1. Obtain the IP address. Enter "http://www.xxx.edu.cn/" in the address bar of the browser and submit it, first it will look up in the DNS local cache table, if there is, directly tell the IP address. If no IP address is found, the gateway DNS must be searched. If no IP address is found, the IP address is returned to the browser.
2. Establish a TCP connection. After obtaining the IP address, you can establish a TCP connection with the requested server. You can find SYN, ack, and these identifiers are used for synchronization.
3. After the connection is established, an HTTP request is sent to the server (as you can see ). For http1.0, the TCP connection is released after each request is completed.

(In, the corresponding IP address cannot be found locally because it is the first time you visit the website)


(The second visit to the same website within a short time)

 

 

previous section" process Introduction ". We have a general understanding of the HTTP request process, this article describes how to use Telnet to simulate HTTP requests --- access Baidu.
Let's get started!
1. Open "run"-> cmd to enter the command environment.
2. Enter "Telnet www.baidu.com 80". Press enter and the screen is black, now we can use the shortcut key "Ctrl +] (right brackets)" to enable the local ECHO function, so that we can see what we are playing, (note that the execution process in this phase and the following processes require the operation time to be as short as possible, because a long time will be considered to be disconnected .)

3. Click Enter to edit the status.
4. Enter "Get/HTTP/1.1" and press Enter. In the second paragraph, enter "Host:" And press enter to complete a simple HTTP request, then I submitted the request to the server as long as I press Enter. (Let's take a look at what this means: Get indicates the request method,/indicates the file in the root directory of the request, HTTP/1.1 indicates the HTTP protocol version, and host is a message header, according to some friends, a "Host:" must be added to version 1.1. However, after my experiment, I found that "Host:" can still send requests normally without adding "Host:", but get HTTP must be capitalized, otherwise, the request cannot be sent)

5. We do not need to do this step to receive the server's return, because after we send the request, we only need a few seconds to receive the response from the server.

6. In this way, the request is complete. Below we search in Baidu "1", the address in the browser should be: http://www.baidu.com/s? WD = 1. Check the request.

How are you doing? The above is only a GET request, of course, you can also use the POST method for the request, but post I am not convenient to do experiments, so I will not write it. For details about the format, refer:
Post/localhost/login. aspx HTTP/1.1
Host:
Content-Type: Application/X-WWW-form-urlencoded
Content-Length: 10

Uid = xxxxxx

Refer:
1. Explanation of the HTTP protocol
2. For details about HTTP request headers, refer to: Response

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.