HTTP protocol and web nature

Source: Internet
Author: User

When you type "http://www.cnblogs.com/#" in the address bar of your browser, click the next hop to show what you are looking at. It will be the first page of the blog ). As a developer, especially a web developer, I think it is necessary for you to understand this series of processing processes. During this periodHow do browsers and servers deal with each other? What does the server do? How does the Browser display the webpage to the user ?......

There are too many questions and details. Frankly speaking, to thoroughly understand each of the above questions and handle the details, at least ten books are required. The so-called "no limit at the bottom layer" is required, in addition, the implementation and processing processes of different Web server and Server programming languages are different (but they are essentially the same ). In this article, I will explain the nature of web development based on the relevant knowledge of HTTP. Whether you are engaged in. net, J2EE, php development, and so on, you cannot do without these features. I hope you will have some new gains and insights after reading this article. Due to my limited level and experience, it is inevitable that there will be errors. Please forgive me.

 

What is the HTTP protocol (Hypertext Transfer Protocol, Hypertext Transfer Protocol )?

The so-called agreement refers to the specifications observed by both parties. HTTP is a standard for "communication" between browsers and servers. We are looking at the space, and Weibo is all using the HTTP protocol. Of course, there are far more than these applications.

I have always heard that HTTP belongs to the "application layer protocol" and is based on the TCP/IP protocol. This is not hard to understand. If you have taken a "Computer Network" course in college, you will be aware of the OSI Layer-7 reference protocol (I did not remember it at the time ). If you have been familiar with Socket network programming, you should understand the two widely used communication protocols TCP and UDP (establish connections, hold hands three times, and so on). Of course, this is not the focus of this Article ).

Since TCP/UDP is a widely used network communication protocol, why is there an extra HTTP protocol?

I have written a simple web server processing software by myself, according to my inference (not necessarily accurate ). The UDP protocol is unreliable and insecure, which obviously cannot meet the needs of Web applications.

The TCP protocol is based on connections and three-way handshakes. Although it is reliable, it has certain defects. But imagine that a common C/S architecture software can connect up to thousands of clients at the same time, while it is common for websites with B/S architecture to have 100,000 people online at the same time. If 100,000 clients and servers remain connected, how can the server meet the requirements?

This derives from the HTTP protocol. TCP-based Reliability connection. In other words, the server immediately closes the connection and releases resources after the request. In this way, both resource availability and TCP reliability are ensured.

Because of this, we usually say that the HTTP protocol is "stateless", that is, "the server does not know what your client is doing ", in fact, it is largely based on performance considerations. So that later we had something like session.

 

Practical preparations:

In terms of network monitoring, there is an excellent software called sniffer on the Windows platform, which is also frequently used by many "hackers. We recommend that you use

A tool called httpwatch. (Unfortunately, this tool is charged. You can do what you do, you know ). After the installation is complete, you can open it directly in tools of IE browser (Firefox is also supported currently ). :

 

 

 

 

 

 

 

Click record to start monitoring and record HTTP messages. The functions of the STOP and clear buttons are not described here. Let's talk with an instance. The following is what I recorded when I accessed the main. ASPX page. The detailed information of the HTTP message is clearly displayed,

To learn about the HTTP protocol, you need to understand the HTTP request and Response (of course, there are also get, post and other request methods, status code, Uri, mime, etc)
First, let's look at the HTTP request message (that is, the message that the browser threw to the server ):

An HTTP request represents the data sent from the client browser to the server. A complete HTTP request message, including one request line, several message headers (request headers), line breaks, and entity content
Request Line: Describes the client request method, request Resource Name, and HTTP Version Number. Example: Get/book/Java. html HTTP/1.1
The request header (message header) contains (the Host Name of the server requested by the client, the environment information of the client, and so on): Accept: indicates the server. The data type supported by the client (for example, accept: text/html, image/*) Accept-charset: Used to tell the server that the client uses the encoding format accept-encoding: Used to tell the server that the client supports the data compression format accept-language: client language environment HOST: the host name that the client accesses through this server. If-modified-since: the client uses this header to tell the server that the cache time of the resource is Referer: the client uses this header to tell the server, which resource does the client access the server? (Anti-leech) User-Agent: the client uses this header to tell the server that the client's software environment (operating system, browser version, etc.) COOKIE: the client uses this header to send coockie information to the server connection: Tell the server whether to keep the connection date after the request is complete: Tell the server the time of the current request
(Line feed) object content: refers to the entity data sent to the server by the browser over HTTP. For example, name = Dylan & id = 110 (the value sent to the server through URL during GET requests. The value sent to the server through the form when a POST request is sent)
Let's look at the HTTP Response Message (returned by the server to the browser ):
An HTTP response indicates the data that the server sends back to the client. It includes a status line, several message headers, and entity content.
The Response Header (message header) contains: Location: Does this header match the 302 status? It is used to tell the client who is to find the server: the server uses this header to tell the Browser Server Type content-encoding: tell the browser the server's data compression format Content-Length: Tell the browser the length of the sent data Content-Type: Tell the browser the type of the sent data last-modified: tell the browser the current resource cache time Refresh: Tell the browser how long it will take to refresh content-Disposition: Tell the browser to open data by downloading. Example: context. response. addheader ("content-disposition", "attachment: filename=aa.jpg"); context. response. writefile ("aa.jpg"); Transfer-encoding: tells the browser that the encoding format of the transmitted data is etag: cache-related header (which can be updated in real time) expries: tell the browser how long the resource is cached. If it is-1 or 0, it indicates no cache-control: control the browser not to cache data no-Cache Pragma: control the browser not to cache data no-Cache
Connection: whether to disconnect after the response is complete. Close/keep-alive Date: tells the browser that the server response time

After understanding the above HTTP request messages and response messages, I believe you have a deep understanding of the HTTP protocol. For more details about the HTTP protocol, referHttp rfc document.

The general procedure is: the browser sends a request to the server first. After the server receives the request, it processes the request, encapsulates the response packet, and then sends it back to the browser. After the browser obtains the response message, it then renders the webpage through the browser engine, parses the DOM tree, parses the JavaScript engine, and executes the script operation. The plug-in does what the plug-in should do... about the principle of browser rendering, resolution, can refer to the http://kb.cnblogs.com/page/129756/

To put it bluntly, the essence of web is nothing more than request/processing/response. No Web server or any Server programming language can be separated from this essence. The browser parses HTML, images, and other static content and presents it to users. The script engine executes the script code to complete the script code (such as Dom operations and CSS attribute changes, send Ajax requests, etc ).

In my opinion, browser is actually a special client, and B/S architecture is also a special C/S architecture. It is worth mentioning how different web servers and programming languages receive HTTP requests from users. How to handle and respond? Taking the familiar ASP. NET as an example, I used the decompilation tool to view the source code (Microsoft is really good at encapsulation) and analyzed it from the underlying layer,

Due to limited space, we can no longer further analyze the details and underlying implementation of Asp.net and IIS web servers. Because Microsoft's Asp.net technology system is huge and complex. If you have time, I will continue to update the series of articles.

 

 

This article is from http://blog.csdn.net/dinglang_2009.

When you type "http://www.cnblogs.com/#" in the address bar of your browser, click the next hop to show what you are looking at. It will be the first page of the blog ). As a developer, especially a web developer, I think it is necessary for you to understand this series of processing processes. During this periodHow do browsers and servers deal with each other? What does the server do? How does the Browser display the webpage to the user ?......

There are too many questions and details. Frankly speaking, to thoroughly understand each of the above questions and handle the details, at least ten books are required. The so-called "no limit at the bottom layer" is required, in addition, the implementation and processing processes of different Web server and Server programming languages are different (but they are essentially the same ). In this article, I will explain the nature of web development based on the relevant knowledge of HTTP. Whether you are engaged in. net, J2EE, php development, and so on, you cannot do without these features. I hope you will have some new gains and insights after reading this article. Due to my limited level and experience, it is inevitable that there will be errors. Please forgive me.

 

What is the HTTP protocol (Hypertext Transfer Protocol, Hypertext Transfer Protocol )?

The so-called agreement refers to the specifications observed by both parties. HTTP is a standard for "communication" between browsers and servers. We are looking at the space, and Weibo is all using the HTTP protocol. Of course, there are far more than these applications.

I have always heard that HTTP belongs to the "application layer protocol" and is based on the TCP/IP protocol. This is not hard to understand. If you have taken a "Computer Network" course in college, you will be aware of the OSI Layer-7 reference protocol (I did not remember it at the time ). If you have been familiar with Socket network programming, you should understand the two widely used communication protocols TCP and UDP (establish connections, hold hands three times, and so on). Of course, this is not the focus of this Article ).

Since TCP/UDP is a widely used network communication protocol, why is there an extra HTTP protocol?

I have written a simple web server processing software by myself, according to my inference (not necessarily accurate ). The UDP protocol is unreliable and insecure, which obviously cannot meet the needs of Web applications.

The TCP protocol is based on connections and three-way handshakes. Although it is reliable, it has certain defects. But imagine that a common C/S architecture software can connect up to thousands of clients at the same time, while it is common for websites with B/S architecture to have 100,000 people online at the same time. If 100,000 clients and servers remain connected, how can the server meet the requirements?

This derives from the HTTP protocol. TCP-based Reliability connection. In other words, the server immediately closes the connection and releases resources after the request. In this way, both resource availability and TCP reliability are ensured.

Because of this, we usually say that the HTTP protocol is "stateless", that is, "the server does not know what your client is doing ", in fact, it is largely based on performance considerations. So that later we had something like session.

 

Practical preparations:

In terms of network monitoring, there is an excellent software called sniffer on the Windows platform, which is also frequently used by many "hackers. We recommend that you use

A tool called httpwatch. (Unfortunately, this tool is charged. You can do what you do, you know ). After the installation is complete, you can open it directly in tools of IE browser (Firefox is also supported currently ). :

 

 

 

 

 

 

 

Click record to start monitoring and record HTTP messages. The functions of the STOP and clear buttons are not described here. Let's talk with an instance. The following is what I recorded when I accessed the main. ASPX page. The detailed information of the HTTP message is clearly displayed,

To learn about the HTTP protocol, you need to understand the HTTP request and Response (of course, there are also get, post and other request methods, status code, Uri, mime, etc)
First, let's look at the HTTP request message (that is, the message that the browser threw to the server ):

An HTTP request represents the data sent from the client browser to the server. A complete HTTP request message, including one request line, several message headers (request headers), line breaks, and entity content
Request Line: Describes the client request method, request Resource Name, and HTTP Version Number. Example: Get/book/Java. html HTTP/1.1
The request header (message header) contains (the Host Name of the server requested by the client, the environment information of the client, and so on): Accept: indicates the server. The data type supported by the client (for example, accept: text/html, image/*) Accept-charset: Used to tell the server that the client uses the encoding format accept-encoding: Used to tell the server that the client supports the data compression format accept-language: client language environment HOST: the host name that the client accesses through this server. If-modified-since: the client uses this header to tell the server that the cache time of the resource is Referer: the client uses this header to tell the server, which resource does the client access the server? (Anti-leech) User-Agent: the client uses this header to tell the server that the client's software environment (operating system, browser version, etc.) COOKIE: the client uses this header to send coockie information to the server connection: Tell the server whether to keep the connection date after the request is complete: Tell the server the time of the current request
(Line feed) object content: refers to the entity data sent to the server by the browser over HTTP. For example, name = Dylan & id = 110 (the value sent to the server through URL during GET requests. The value sent to the server through the form when a POST request is sent)
Let's look at the HTTP Response Message (returned by the server to the browser ):
An HTTP response indicates the data that the server sends back to the client. It includes a status line, several message headers, and entity content.
The Response Header (message header) contains: Location: Does this header match the 302 status? It is used to tell the client who is to find the server: the server uses this header to tell the Browser Server Type content-encoding: tell the browser the server's data compression format Content-Length: Tell the browser the length of the sent data Content-Type: Tell the browser the type of the sent data last-modified: tell the browser the current resource cache time Refresh: Tell the browser how long it will take to refresh content-Disposition: Tell the browser to open data by downloading. Example: context. response. addheader ("content-disposition", "attachment: filename=aa.jpg"); context. response. writefile ("aa.jpg"); Transfer-encoding: tells the browser that the encoding format of the transmitted data is etag: cache-related header (which can be updated in real time) expries: tell the browser how long the resource is cached. If it is-1 or 0, it indicates no cache-control: control the browser not to cache data no-Cache Pragma: control the browser not to cache data no-Cache
Connection: whether to disconnect after the response is complete. Close/keep-alive Date: tells the browser that the server response time

After understanding the above HTTP request messages and response messages, I believe you have a deep understanding of the HTTP protocol. For more details about the HTTP protocol, referHttp rfc document.

The general procedure is: the browser sends a request to the server first. After the server receives the request, it processes the request, encapsulates the response packet, and then sends it back to the browser. After the browser obtains the response message, it then renders the webpage through the browser engine, parses the DOM tree, parses the JavaScript engine, and executes the script operation. The plug-in does what the plug-in should do... about the principle of browser rendering, resolution, can refer to the http://kb.cnblogs.com/page/129756/

To put it bluntly, the essence of web is nothing more than request/processing/response. No Web server or any Server programming language can be separated from this essence. The browser parses HTML, images, and other static content and presents it to users. The script engine executes the script code to complete the script code (such as Dom operations and CSS attribute changes, send Ajax requests, etc ).

In my opinion, browser is actually a special client, and B/S architecture is also a special C/S architecture. It is worth mentioning how different web servers and programming languages receive HTTP requests from users. How to handle and respond? Taking the familiar ASP. NET as an example, I used the decompilation tool to view the source code (Microsoft is really good at encapsulation) and analyzed it from the underlying layer,

Due to limited space, we can no longer further analyze the details and underlying implementation of Asp.net and IIS web servers. Because Microsoft's Asp.net technology system is huge and complex. If you have time, I will continue to update the series of articles.

 

 

This article is from http://blog.csdn.net/dinglang_2009.

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.