HTTP request to HTTP Request

Source: Internet
Author: User
Tags microsoft iis
HTTP Request

Over the past few days, I have learned about the HTTP protocol, such as HTTP request response. I did not consider this when I wrote my website, that is, the so-called "Trust control". After learning these knowledge points over the past few days, I feel that it is really an improvement. Because I am stupid, I should write a note to record it, if you forget about it, you can study it again. By the way, there may be errors. I hope you can point them out.

1. What is a browser? What is a server?

(1) We have been browsing the webpage. For example, if we go to www.cnblogs.com in the blog site, do we know what our browser and server did when we enter this URL? Let's take a look at the figure below:

(2) When we enter http: // 127.0.0.1: 8080/proscenium/in the browser, the browser requests the background server and the background server returns a webpage to us, so what did the backend server do? We can use Chrome, ie's developer tools, or debugbur, Fiddler, and httpwatch to view the access records of my website.

Note: When we enter the URL and press enter, the browser automatically encapsulates the requested address into an HTTP packet, and the HTTP packet is a string, then, the request is sent to the corresponding IP address and port of the server through socket. The request message format is as follows:

GET/proscenium/HTTP/1.1

HOST: localhost: 8080

Connection: keep-alive

Cache-control: Max-age = 0

User-Agent: Mozilla/5.0 (Windows NT 6.2; wow64) applewebkit/537.1 (khtml, like gecko) Chrome/21.0.1180.89 Safari/537.1

Accept: text/html, application/XHTML + XML, application/XML; q = 0.9, */*; q = 0.8 accept-encoding: gzip, deflate, SDCh

Accept-language: ZH-CN, ZH; q = 0.8 accept-charset: GBK, UTF-8; q = 0.7, *; q = 0.3 COOKIE: Asp. net_sessionid = myc2esb4m0io50gf0t52jvtl

Send the preceding HTTP message to the server. The server parses the HTTP protocol, encapsulates the parsed page into a response message, and sends it back to the browser, the browser will parse the response message sent from the server and display the corresponding information.

HTTP/1.1 200 OK

Cache-control: Private

Content-Type: text/html; charset = UTF-8

Content-encoding: Gzip

Vary: Accept-Encoding

Server: Microsoft-Microsoft IIS/8.0

X-ASPnet-version: 4.0.30319

X-powered-by: ASP. NET

Date: sat, 27 Oct 2012 11:46:29 GMT

Content-Length: 52728

(3) Finally, the above request response process is illustrated using graphs.

(4) When parsing the HTML page of the data sent from the server, the browser parses the data row by row. When the imported file of jquery is added, A request is sent to parse the JS file and parse the file to the same execution format as CSS and images. Therefore, the browser performs the parsing process, of course, there are some special controls (tables ).

(5) We often use the IIS manager on the. NET platform. We can host our website to IIS and view our website.

(6) browser and server Language

1) the browser is only responsible for interpreting and executing HTML + CSS + JavascriptCode

2) The server executable server language. NET and Java are executed by different runtime environments (Framework and JVM) respectively)

(7) What are the differences between static pages and dynamic pages?

1) on the server, it is equivalent to directly reading the file string and returning it to the client browser. (access to the same interface is displayed at any time ).

2) The server is first handed overCompile and run a virtual machine in a language environment, Generate code according to the syntax and return to the client browser. (The access page varies depending on different conditions and times ).

2. http protocol

(1) Web Development deals with the HTTP protocol. You must understand the HTTP protocol, HTTP Protocol Version: HTTP/0.9, HTTP/1.0, and HTTP/1.1.

(2) concepts of HTTP protocol

1) connection: the data transmission channel between the browser and the server. Generally, the connection is closed when the request is complete, and HTTP does not maintain the connection, if the connection is not maintained, the processing speed will be reduced (because the connection establishment speed is slow). If the connection is maintained, the number of client requests processed by the server will be reduced, and the connection server will be able to process more requests.

2) request: the browser sends a "what" message to the server, including the request type, request data, browser information (language, browser version, and other information ).

3) response: the server returns data to the browser's request, including whether the request is successful, Status Code, and other information.

(3) HTTP message structure

(4. http protocol-Request Message format

(5) HTTP protocol-detailed description of request packets

1) Use httpwatch to view the response to a website. After you enter a URL, the browser sends a request to the server. Images, JS, and CSS on the page are in separate requests.

2) Host: send the request to the server

3) Accept-encoding gzip. Deflate indicates that the browser supports gzip and deflate compression.Algorithm

4) Accept-language ZH-CN indicates the language supported by the browser. Many international websites that automatically access the Chinese interface are implemented by reading the value of this header.

5) connection keep-alive. In general, once the Web server sends the request data to the browser, it will close the TCP connection. If the browser or Server adds connection: keep-alive to its header information, the TCP connection remains open after being sent. Therefore, the browser can continue to send requests through the same connection, saving the time required to create a new connection for each request, it also saves network bandwidth.

6) The cookie is the cookie sent by the browser to the server and associated with the current website, so that the server can also read the cookie from the browser.

7) the User-Agent is the version information of the browser. You can use this information to read information about the browser, such as IE or Firefox, supported plug-ins, and. Net versions.

8) Referer: indicates the request address, that is, from that page.

9) Content-Length: indicates the length of the following request body

(6) HTTP protocol-corresponding message format

(7) HTTP protocol-Explanation of corresponding packets

1) when the browser sends a request to the server, the server may be able to process the request successfully, possibly because of failure or access permissions. Will the server tell the browser about the processing result?

1) "200": indicates that the execution is successful, and OK is returned.

2) "302": Found redirection.

3) "400": Bad rquest error request. An invalid HTTP request is sent.

4) "403": Forbidden.

5) "404": Not found not found. This shows you how to access a nonexistent page to view the report.

6) "500": Internal error of the internal server error server. An exception is thrown on the demo page.

7) "503": Service unavailable. This is generally because there are too many people to access. You can use 12306 website experiments. This result may be returned.

2) Segment 1 is successful, and Segment 2 requires further processing of the request. Segment 2 indicates a client request error and Segment 2 indicates a server error.

3) server: Cassini/3.5.0.5 indicates the server type.

4) Content-Type: text/html; charset = UTF-8 indicates the type of the returned data

5) The server uses Content-Type to tell the client the type of response data, so that the browser can process the data according to the type of returned data, for text type, the content is displayed directly. For HTML type, the content is displayed in a browser. For download type, a download tool is displayed.

6) Common Content-Type: text/html, image/GIF, image/JPEG, text/plain, text/JavaScript, application/X-Excel, application/octet-stream (binary file)

7) Content-Length: 19944Response StyleThe length of bytes. the packet header is only a description. The returned data (such as HTML text and image data) is in the content after two carriage returns.

8) Introduction to HTTP

1) HTTP is stateless and does not remember "What was the last request". Therefore, even JavaScript, CSS, and jpg files on the same page must be repeatedly submitted for accept-language, accept-encoding, Cookie, etc.

2) if there are images, CSS, JS and other external files on the webpage, images, CSS, and JS are all in separate requests, that is, not all content on the page is completed in one request, but a request for each resource.

3) Generally, only the browser requests data from the server, and the server responds to the browser. The server does not actively push data to the browser. This is a security consideration, it is also to improve the server's performance. If the server needs to push data to the browser, it needs to use additional technologies such as serverpush (Ajax requests the latest data from the server over a period of time.

4) HTTP is the "request-response" working mode.

(9) simulate the HTTP protocol process.

1) the function of this small project is: Graphic Display

2) the effect is:

3) the code is: http://files.cnblogs.com/hanyinglong/AnalogIISDemo.zip

Over the past few days, I have learned about the HTTP protocol, such as HTTP request response. I did not consider this when I wrote my website, that is, the so-called "Trust control". After learning these knowledge points over the past few days, I feel that it is really an improvement. Because I am stupid, I should write a note to record it, if you forget about it, you can study it again. By the way, there may be errors. I hope you can point them out.

1. What is a browser? What is a server?

(1) We have been browsing the webpage. For example, if we go to www.cnblogs.com in the blog site, do we know what our browser and server did when we enter this URL? Let's take a look at the figure below:

(2) When we enter http: // 127.0.0.1: 8080/proscenium/in the browser, the browser requests the background server and the background server returns a webpage to us, so what did the backend server do? We can use Chrome, ie's developer tools, or debugbur, Fiddler, and httpwatch to view the access records of my website.

Note: When we enter the URL and press enter, the browser automatically encapsulates the requested address into an HTTP packet, and the HTTP packet is a string, then, the request is sent to the corresponding IP address and port of the server through socket. The request message format is as follows:

GET/proscenium/HTTP/1.1

HOST: localhost: 8080

Connection: keep-alive

Cache-control: Max-age = 0

User-Agent: Mozilla/5.0 (Windows NT 6.2; wow64) applewebkit/537.1 (khtml, like gecko) Chrome/21.0.1180.89 Safari/537.1

Accept: text/html, application/XHTML + XML, application/XML; q = 0.9, */*; q = 0.8 accept-encoding: gzip, deflate, SDCh

Accept-language: ZH-CN, ZH; q = 0.8 accept-charset: GBK, UTF-8; q = 0.7, *; q = 0.3 COOKIE: Asp. net_sessionid = myc2esb4m0io50gf0t52jvtl

Send the preceding HTTP message to the server. The server parses the HTTP protocol, encapsulates the parsed page into a response message, and sends it back to the browser, the browser will parse the response message sent from the server and display the corresponding information.

HTTP/1.1 200 OK

Cache-control: Private

Content-Type: text/html; charset = UTF-8

Content-encoding: Gzip

Vary: Accept-Encoding

Server: Microsoft-Microsoft IIS/8.0

X-ASPnet-version: 4.0.30319

X-powered-by: ASP. NET

Date: sat, 27 Oct 2012 11:46:29 GMT

Content-Length: 52728

(3) Finally, the above request response process is illustrated using graphs.

(4) When parsing the HTML page of the data sent from the server, the browser parses the data row by row. When the imported file of jquery is added, A request is sent to parse the JS file and parse the file to the same execution format as CSS and images. Therefore, the browser performs the parsing process, of course, there are some special controls (tables ).

(5) We often use the IIS manager on the. NET platform. We can host our website to IIS and view our website.

(6) browser and server Language

1) the browser is only responsible for interpreting and executing HTML + CSS + JavaScript code

2) The server executable server language. NET and Java are executed by different runtime environments (Framework and JVM) respectively)

(7) What are the differences between static pages and dynamic pages?

1) on the server, it is equivalent to directly reading the file string and returning it to the client browser. (access to the same interface is displayed at any time ).

2) The server is first handed overCompile and run a virtual machine in a language environment, Generate code according to the syntax and return to the client browser. (The access page varies depending on different conditions and times ).

2. http protocol

(1) Web Development deals with the HTTP protocol. You must understand the HTTP protocol, HTTP Protocol Version: HTTP/0.9, HTTP/1.0, and HTTP/1.1.

(2) concepts of HTTP protocol

1) connection: the data transmission channel between the browser and the server. Generally, the connection is closed when the request is complete, and HTTP does not maintain the connection, if the connection is not maintained, the processing speed will be reduced (because the connection establishment speed is slow). If the connection is maintained, the number of client requests processed by the server will be reduced, and the connection server will be able to process more requests.

2) request: the browser sends a "what" message to the server, including the request type, request data, browser information (language, browser version, and other information ).

3) response: the server returns data to the browser's request, including whether the request is successful, Status Code, and other information.

(3) HTTP message structure

(4. http protocol-Request Message format

(5) HTTP protocol-detailed description of request packets

1) Use httpwatch to view the response to a website. After you enter a URL, the browser sends a request to the server. Images, JS, and CSS on the page are in separate requests.

2) Host: send the request to the server

3) Accept-encoding gzip. Deflate indicates that the browser supports gzip and deflate compression algorithms.

4) Accept-language ZH-CN indicates the language supported by the browser. Many international websites that automatically access the Chinese interface are implemented by reading the value of this header.

5) connection keep-alive. In general, once the Web server sends the request data to the browser, it will close the TCP connection. If the browser or Server adds connection: keep-alive to its header information, the TCP connection remains open after being sent. Therefore, the browser can continue to send requests through the same connection, saving the time required to create a new connection for each request, it also saves network bandwidth.

6) The cookie is the cookie sent by the browser to the server and associated with the current website, so that the server can also read the cookie from the browser.

7) the User-Agent is the version information of the browser. You can use this information to read information about the browser, such as IE or Firefox, supported plug-ins, and. Net versions.

8) Referer: indicates the request address, that is, from that page.

9) Content-Length: indicates the length of the following request body

(6) HTTP protocol-corresponding message format

(7) HTTP protocol-Explanation of corresponding packets

1) when the browser sends a request to the server, the server may be able to process the request successfully, possibly because of failure or access permissions. Will the server tell the browser about the processing result?

1) "200": indicates that the execution is successful, and OK is returned.

2) "302": Found redirection.

3) "400": Bad rquest error request. An invalid HTTP request is sent.

4) "403": Forbidden.

5) "404": Not found not found. This shows you how to access a nonexistent page to view the report.

6) "500": Internal error of the internal server error server. An exception is thrown on the demo page.

7) "503": Service unavailable. This is generally because there are too many people to access. You can use 12306 website experiments. This result may be returned.

2) Segment 1 is successful, and Segment 2 requires further processing of the request. Segment 2 indicates a client request error and Segment 2 indicates a server error.

3) server: Cassini/3.5.0.5 indicates the server type.

4) Content-Type: text/html; charset = UTF-8 indicates the type of the returned data

5) The server uses Content-Type to tell the client the type of response data, so that the browser can process the data according to the type of returned data, for text type, the content is displayed directly. For HTML type, the content is displayed in a browser. For download type, a download tool is displayed.

6) Common Content-Type: text/html, image/GIF, image/JPEG, text/plain, text/JavaScript, application/X-Excel, application/octet-stream (binary file)

7) Content-Length: 19944Response StyleThe length of bytes. the packet header is only a description. The returned data (such as HTML text and image data) is in the content after two carriage returns.

8) Introduction to HTTP

1) HTTP is stateless and does not remember "What was the last request". Therefore, even JavaScript, CSS, and jpg files on the same page must be repeatedly submitted for accept-language, accept-encoding, Cookie, etc.

2) if there are images, CSS, JS and other external files on the webpage, images, CSS, and JS are all in separate requests, that is, not all content on the page is completed in one request, but a request for each resource.

3) Generally, only the browser requests data from the server, and the server responds to the browser. The server does not actively push data to the browser. This is a security consideration, it is also to improve the server's performance. If the server needs to push data to the browser, it needs to use additional technologies such as serverpush (Ajax requests the latest data from the server over a period of time.

4) HTTP is the "request-response" working mode.

(9) simulate the HTTP protocol process.

1) the function of this small project is: Graphic Display

2) the effect is:

3) the code is: http://files.cnblogs.com/hanyinglong/AnalogIISDemo.zip

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.