Topic Two: HTTP protocol detailed

Source: Internet
Author: User
Tags response code domain name server file transfer protocol

After we have developed the Web application with ASP., when the user enters a URL in the browser to send an HTTP request to the server, then the application layer HTTP protocol is used, in the previous topic we briefly introduced the knowledge of the network protocol, mainly for the following HTTP protocol to do a foreshadowing, only to the HTT The P protocol has a clear understanding that when we develop a Web application with ASP. NET technology, we can think of our application from the aspect of the network protocol rather than just the procrastination of the server control, which also helps us to develop our own custom Web server. Here I want to at the same time my understanding of the nature of ASP and share with you, if there is anything wrong, also please point out that, first of all, when we design an algorithm to clear the input parameters and the return of the algorithm (the algorithm is also a processing program), in fact, ASP. NET developed Web page can be understood as a processing program , because what we see in the Web browser is an HTML document (HTML is the output of the program after the ASP.), but the input parameter is an HTTP request that the user enters via the browser (which can be said to be a URI address of the request). This technology helps us to translate the requested ASPX page into an HTML document, and then the HTML document sends the HTML document to the browser via the HTTP protocol, which is then tagged (the HTML document is just a string of strings, and if there is no browser parsing we see some strings instead of the visual bounds Resolved to a visual interface. Such a Web request will also end. We will also share with you some of the objects that we have done in the back of the ASP, and here is the introduction to the HTTP protocol.

I. Introduction to the HTTP protocol

HTTP Chinese is Hypertext Transfer Protocol, easy to understand from the name, the HTTP protocol is the Hypertext Markup Language of the document (that is, HTML document) from the Web service to the client's browser. It belongs to an application layer protocol.

Second, the work process of the network

When a user wants to access a webpage on the network, there are a few steps to follow:

    1. The user first to determine the URL of the Web page file (Uniform Resource Locator, that is, the home address of the Web page on the network, through this address can find this page) such as www.cnblogs.com
    2. The browser sends a request to DNS (domain name server), tells DNS said: "I want to convert www.cnblogs.com to its defined IP address", here can simply interpret DNS as a dictionary, know domain name can know domain name for IP address, they have this a mapping relationship
    3. After the DNS receives the request, it starts querying and returns the results back to the browser. If the domain name is www.cnblogs.com the corresponding IP address is 61.155.169.116
    4. After you know the IP address, the browser sends a TCP connection request to the host with the IP address 61.155.169.116 (the HTTP protocol is based on the Transport Layer TCP), and the 80 port is the default port for the server to provide the Web service.
    5. After the connection is established, the browser issues an HTTP request such as GET http://www.cnblogs.com/HTTP/1.1
    6. Send an HTML file to the browser when the server that has the domain name www.cnblogs.com receives the request
    7. When the file is sent out, the server actively shuts down the TCP connection.
    8. The browser receives the transmitted page and displays
    9. If the HTML file contains a picture, also establish a TCP connection with the server so that you can download the picture

In the above steps, after the browser makes a request, how to download the HTML document on a server to the host requesting the Web page? This process is done by HTTP, that is, to complete the transmission of Hypertext files, the HTTP protocol is the basis of the Web server.

Second, HTTP request

The HTTP request consists of three parts: the request line, the request header, and the request data, and the format of an HTTP request is generally as follows:

  请求方法 URL HTTP版本号   请求头信息     <一个空行>   请求数据The HTTP request method is in the following table:

Method

Describe

Get

Returns the document referred to by the URL, typically used to request a Web page download

Head

Requests the header of the document, which resembles the Get method, except that the Web server returns the header information for the specified document

Post

Instead of a GET method, it requests the server to accept the specified document, but it does not replace the existing document, but appends the new data to it.

Put

It is similar to the Get method by replacing the content in the specified document with data from the client, enabling customers to send files such as Web pages to a remote Web server

Delete

Requesting the server to delete the specified page

Options

Allow clients to view server performance

Trace

Used to test the message recycling process that allows clients to view

Often using the Get and post methods, when the request is made using the Get method, the request data is empty, so the HTTP request line at this time consists of two parts: the request line and the request header information, below we look at the specific HTTP instance:

When in the browser address bar input: www.cnblogs.com, at this time we are equivalent to send an HTTP request, specifically:


And you can see that the Web page contains picture scripts and other files, the client will continue to make requests with the server, request the necessary pictures and script files.

Add: By a friend's message, here I add, now usually only to establish a TCP connection, through the HTPP request Header connetion Field indicated, when the server received a connection:keep-alive request, It also adds an identical field to the response header to use the keep-alive. In this way, the HTTP connection between the client and the server is maintained and will not be disconnected (except in some special cases) when the client sends another request, the established connection is used.

The following information about the request header is described below:

Accept: Indicates the type of data received by the client. For example, accept:text/html indicates that the client can receive text of HTML type

User Agent: Indicates the type of client software

Referer: Represents the URL of the previous connection, such as jumping to the previous page URL on this page.

is a Get method to download an HTML file to this example browser to display the process, when we log in the Blog Park home page point after entering the user name and password after the confirmation button, at this time we send the HTTP request is through the Post method, the following is a:

As you can see, there is a blank line in the HTTP request sent through the Post method (after the blank line is the request data), and the Get method does not make the request.

 

Third, HTTP response

Similarly, the HTTP response is made up of three parts: the status line, the response header, and the response data, and the HTTP response format is as follows:

  状态行   响应头   <一个空行>   响应数据   The status line starts with the HTTP version number, followed by 3 as a number, represents the response code, and the response code tells the client whether the server produced the expected response. such as http/1.1 OK.

Five response codes are defined in http/1.1:

1XX: Indication information--Indicates that the request has been received and continues processing
2XX: Success-Indicates that the request has been successfully received, understood, accepted
3XX: Redirect--further action is required to complete the request
4XX: Client Error--Request syntax error or request not implemented
5XX: Server-side error-the server failed to implement a legitimate request

A description of the specific response code is shown below:

The HTTP response header is used by the server to provide the client with the requested document information or the service-side status information.

Iv. Summary

Here is the end of this article, the HTTP protocol is only one of the protocols in the application layer, the application layer has other protocols, such as FTP (File Transfer Protocol), SMTP (e-mail protocol), and so on, these protocols are described later. The following topic intends to apply the HTTP protocol simply by customizing a simple Web server to simulate the process of sending an HTTP request and the server returning a response after we normally enter the URL in the browser.

Transferred from: http://www.cnblogs.com/zhili/archive/2012/08/18/HTTP.html

Topic Two: HTTP protocol detailed

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.