After we use Asp.net technology to develop Web applications, when users enter a web site in the browser, they send an HTTP request to the server. In this case, the application layer HTTP protocol is used, in the previous topic, we briefly introduced the knowledge of the network protocol, mainly to pave the way for the next talk about the HTTP protocol. We only have a clear understanding of the HTTP protocol, in this way, when we use Asp.net technology to develop Web applications, we can think about our applications in terms of network protocols instead of simply dragging the server control, this will also help us develop a custom web server.
Here I want to share with you my understanding of the nature of Asp.net. If there is anything wrong with it, please note that, first of all, when designing an algorithm, we need to specify the input parameters and the return of the algorithm (the algorithm is also a processing program). In fact, the web page developed by Asp.net can be understood as a processing program, because all we see in the Web browser are HTML documents (HTML is the output of the program after the Asp.net web page processing, that is, the return of the algorithm ), however, the input parameter is an HTTP request (a URI address of the request) entered by the user through the browser. Asp.net helps us translate the requested ASPX page into HTML documents, then, the HTML document sends the HTML document to the browser through the HTTP protocol, and then the browser puts this tag (the HTML document is just a string. If there is no browser parsing, we will see some strings, instead of a visualized interface) is resolved to a visualized interface. This Web Request ends. I will share with you some of the objects behind Asp.net for us later. Here I will go back to the introduction of HTTP protocol.
1. Introduction to HTTP
HTTP Chinese is a hypertext transfer protocol, which is easy to understand in terms of name. HTTP is to transfer hypertext markup language documents (HTML documents) from web services to the client browser. It belongs to an application layer protocol.
Ii. Network Work Process
To access a webpage on the network, follow these steps:
1. the user must first determine the URL of the webpage file (Uniform Resource Locator, that is, the home address of the webpage on the network, through which the webpage can be found), such as www.cnblogs.com
2. the browser sends a request to the DNS (Domain Name Server) and tells the DNS: "I want to convert www.cnblogs.com to the IP address it defines." Here, we can simply regard DNS as a dictionary, if you know the domain name, you can know the IP address of the domain name. They have this ing relationship.
3. After receiving the request, DNS starts querying and returns the result to the browser. If the domain name is www.cnblogs.com, the corresponding IP address is 61.155.169.116.
4. after knowing the IP address, the browser sends a TCP connection request (based on TCP at the transport layer) to the host with the IP address 61.155.169.116 and port 80 ), port 80 is the default port for the Web service provided by the server.
5. After a connection is established, the browser sends an HTTP request, such as get http://www.cnblogs.com/HTTP/1.1
6. When the server with the domain name www.cnblogs.com receives the request, it sends an HTML file to the browser.
7. After the file is sent, the server closes the TCP connection.
8. The browser receives and displays the transferred page.
9. If an HTML file contains an image, you must establish a TCP connection with the server to download the image.
In the steps described above, after a browser sends a request, how does one download the HTML document on a server to the host of the requested webpage? This process is completed by HTTP, that is, transfer of Hypertext files. HTTP is the foundation of web servers.
Ii. http request
An HTTP request consists of three parts: request line, request header, and request data. The format of an HTTP request is generally as follows:
Request Method url http Version Number request header information <a blank line> request data
The following table lists the HTTP request methods:
The get and post methods are often used. When the get method is used to send a request, the request data is empty. Therefore, the HTTP request line consists of two parts: request Line and request header information. The following figure shows the specific HTTP instance:
When you enter www.cnblogs.com in the address bar of the browser, an HTTP request is sent, specifically:
In addition, when the webpage contains image scripts and other files, the client will continue to send a request with the server to request the images and script files required.
Supplement: in a friend's message, I add that only one TCP connection is usually established and specified through the connection FIELD IN THE htpp request header, when the server receives a request with connection: keep-alive, it also adds the same field to the response header to use keep-alive. In this way, the HTTP connection between the client and the server will be maintained and will not be disconnected (except in some special cases). When the client sends another request, it will use this established connection.
The following describes the request header information:
Accept: indicates the Data Type received by the client. For example, accept: text/html indicates that the client can receive HTML-type text.
User Agent: client software type
Referer: indicates the URL of the previous connection, for example, the URL of the previous page to jump.
It is a process of downloading an HTML file to the browser in this example through the get method. When we log on to the blog garden homepage, enter the user name and password, and click "OK, in this case, the HTTP request is sent through the post method. The following is:
It can be seen that there is a blank line in the HTTP request sent through the post method (the request data is after the blank line), but not in the request sent by the get method.
Iii. Http response
Similarly, an HTTP response is composed of three parts: Status line, response header, and response data. The HTTP Response format is as follows:
Status line response header <one blank line> response data
The status line starts with the HTTP version number, followed by 3, representing the response code. The response code is used to tell the client whether the server has produced the expected response. For example, HTTP/1.1 200 OK.
Five Response codes are defined in HTTP/1.1:
1xx: indicates that the request has been received and continues to be processed.
2XX: Success-indicates that the request has been successfully received, understood, and accepted
3xx: Redirection-further operations are required to complete the request
4xx: client error-the request has a syntax error or the request cannot be implemented
5xx: Server Error -- the server fails to fulfill the valid request
For details about the response code, see:
The HTTP response header is used by the server to provide the request documentation or server status information to the client,
Iv. Summary
This article is just over. The HTTP protocol is only one of the protocols in the application layer. There are other protocols in the application layer, such as FTP (file transfer protocol) and SMTP (email protocol) these protocols will be introduced later. The next topic intends to apply the HTTP protocol only by customizing a simple web server to simulate the process of entering a URL in a browser and then sending an HTTP request and a response from the server.
Link: http://www.cnblogs.com/zhili/archive/2012/08/18/HTTP.html