In this blog, I mainly talk about the HTTP protocol, because we developed references based on web pages (B/S ).ProgramDevelopment, so we have to deal with the HTTP protocol. This blog is a preliminary study of how to deal with the HTTP protocol.
- 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, HTTP/1.1, currently, all mainstream versions are HTTP/1.1.
(2) HTTP protocol analysis tools
1) the content of the debugbar and HTTP (s) tags is free of charge and can only analyze the content in the current browser.
2) httpwatch, charged, can only analyze the content in the current browser.
3) httpanalyzer, charged, can analyze all the HTTP data on the computer.
(3) concepts of HTTP protocol
1) connection: the data transmission channel between the browser and the server. Generally, the connection is closed after the request is complete and will not be kept.
2) request: the browser sends "I want to..." to the server ......" Message, including the request type, request data, browser information (language, browser version, etc ).
3) response: the server returns data for browser requests, including success or error codes.
- HTTP Request Message
(1) Use httpwatch to view the response to a website (using discu2n to test the Environment). After you type a website, the browser sends a request to the server. js and images on the page, CSS is in a separate request.
(2) GET/HTTP/1.1 indicates to request the homepage in get mode to the server, and HTTP/1.1 protocol is used.
(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. After entering many websites, it is automatically implemented by reading the value of this header for international websites on the Chinese interface.
(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 in its header information, the TCP connection remains open after being sent, so 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) Cookies are the cookies associated with the current website sent by the browser to the server, so that the server can also read the cookies from the browser.
(7) The User-Agent is the version information of the browser. You can use this information to read whether the browser is IE or Firefox, the supported plug-ins, and the. NET version.
- HTTP response code
(1) When a browser sends a request to the server, the server may be able to process the request successfully, fail, or have no access permission, and the server will notify the browser of the result through the response code.
1) "200": OK.
2) "301": permanent transfer of moved permanently.
3) "302": Found is temporarily transferred.
4) "307": tempoay redirect.
5) "400": Bad request error request. The request that sends an error does not meet the HTTP protocol requirements.
6) "401": unauthoried is not authenticated. Generally, the user name and password are required for logon.
7) "403": Forbidden.
8) "404": Not found not found (*).
9) "500": the internal server error.
10) "503": Server unavailable: Generally, there are too many visitors.
(2) Paragraph 200 is successful, and paragraph 300 requires further processing of the request. Section 400 indicates a client request error, and section 500 indicates a server error.
- Packets returned by the server
(1) server: Cassini/3.5, 0.5 indicates the server type.
(2) Content-Type: text/html; charset = UTF-8 indicates the type of the returned data.
(3) The server uses Content-Type to notify the client of the response data type, so that the browser processes the data according to the returned data type and displays the data as an image, if it is text type, the content is displayed directly. If it is HTML type, the content is displayed in the browser. If it is download type, a download tool is displayed.
(4) Common Content-Type: text/html, image/GIF, image/JPEG, text/plain, text/JavaScript, application/X-Excel, application/octet-stream (binary file ).
(5) Content-Length: 19944 indicates the length of the subsequent data message body. The message header is only a description and the specific data returned (such as HTML text and image data) in the content after two carriage returns.
- Other HTTP
(1) If there are external files reported by images, CSS, and JS on the webpage, the images, CSS, and JS are all in separate requests, that is, not all the content of the page is completed in one request, but a request for each resource.
(2) Generally, only when the browser requests the server, the server responds to the data from the browser and does not actively push data to the browser. This is a security consideration, it is also to improve the server performance. If the server needs to push data to the browser, additional technologies such as serverpush are required.
(3) HTTP is the "request-response" method. Therefore, the page is constantly refreshed. If you do not want to refresh the page, you must use Ajax technology.
- Example of a Request Response Model
(1) click the button to delete a table and use a hyperlink to delete the table.
1) create a new HTML page named delete.htm. Create a general processing program named Delete. ashx, and writeCodeAs follows:
1Context. response. contenttype ="Text/html";2 3StringName = context. request ["Name"];4 5Context. response. Write (name +"Deleted");
Write the following code on the delete.htm page:
1 <Form action = " Delete. ashx " Id = " Form1 " Method = " Get " > 2 3 <Input type = " Hidden " Name = " Name " Id = " Name " /> 4 5 <Table> 6 7 <Tr> <TD> name </TD> <TD> age </TD> <TD> operation </TD> </tr> 8 9 <Tr> <TD> Tom </TD> <TD> 20 </TD>10 11 <TD> <a href = " Delete. ashx? Name = Tom " > Delete </a> 12 13 <! -- <Input/> the role of the control is to obtain the name value first, and then execute the form --> 14 15 <Input type = " Button " Value = " Delete " Onclick = " Document. getelementbyid ('name'). value = 'Tom '; document. getelementbyid ('form1'). Submit (); " /> </TD> 16 17 </Tr> 18 19 <Tr> <TD> Jerry </TD> <TD> 30 </TD> <a href = " Delete. ashx? Name = Jerry " > Delete </a> </TD> </tr>20 21 </Table> 22 23 </Form>
2) on the new web form page, enter the following operation code under the page. The code in page_load is:
1If(Ispostback)2 3 {4 5StringName = request ["Name"];6 7Response. Write (name +"Deleted");8 9}
The page layout is:
1 <Body> 2 3 <Form ID = " Form1 " Runat = " Server " Method = " Post " > 4 5 <Asp: textbox id = " Textbox1 " Runat = " Server " > </ASP: textbox> 6 7 <Input type = " Hidden " Name = " Name " Id = " Name " /> 8 9 <Div> 10 11 <Table> 12 13 <Tr> <TD> name </TD> <TD> age </TD> <TD> operation </TD> </tr> 14 15 <Tr> 16 17 <TD> Tom </TD> <TD> 20 </TD> <TD> 18 19 <Input type = " Button " Value = " Delete " Onclick = " Document. getelementbyid ('name'). value = 'Tom '; document. getelementbyid ('form1'). Submit () " /> 20 21 <A href = " Javascript: Document. getelementbyid ('name'). value = 'Tom '; document. getelementbyid ('form1'). Submit () " > Delete </a> 22 23 </TD> 24 25 </Tr> 26 27 <Tr> <TD> Jerry </TD> <TD> 30 </TD> <a href = " Delete. aspx? Name = Jerry " > Delete </a> </TD> </tr> 28 29 </Table> 30 31 </Div> 32 33 </Form> 34 35 </Body>
(2) In Asp.net, the row buttons and row hyperlinks in the data binding control are implemented in different ways. In listview, the buttons and hyperlinks are deleted in two ways, the button is used to submit the row ID to the server through the form, and the row hyperlink is submitted to the processing page through the hyperlink URL through the get method, the hyperlink method does not submit all form information, so many server-side controls cannot be used in advanced usage.
(3) rewrite with Aspx. Because the hidden fields such as viewstate are not submitted to the server for the hyperlink, ispostback is false for processing, while the button is submitted for form, so ispostback = true, you can write the JavaScript For Form submission in the href of the hyperlink, which is the principle of linkbutton in webform.
(4) because the client and server are on two computers, the variables on both sides cannot be read from each other or the functions on both sides can be called from each other. Therefore, if it seems to be done, the client variable value must be submitted to the server as a form field, or the server can print the server variable to the client code.
Note: The HTTP protocol is mentioned here. The next blog is the basic principle of Wen's development. We hope we can learn it together. Our group number is:159227188And you are welcome to discuss it here.