Analysis of Web Development--http Protocol

Source: Internet
Author: User
Tags apache tomcat

  Http, or Hypertext Transfer Protocol, is based on the TCP/IP protocol. In the process of web development, the HTTP protocol is very important, the interaction between the browser and the server is based on the HTTP protocol. HTTP protocol If the full explanation will have a lot of content, here the main analysis of the HTTP protocol request and Reply content format, the corresponding message header and several status codes.

  One, HTTP request

complete HTTP requests include: A request line, several message headers, the entity content of several requests (the message header and the request content are separated by a blank line );  1. Request Line used to describe the client's request, the requested resource name, and the version number of the HTTP protocol used;    such as: get/test/hello.html http/1.1; The GET becomes the request mode, the request method is: Post,, OPTIONS, TRACE, put commonly used are: post, get. Where http/1.1 represents the protocol version number, http/1.0 is a short connection, http/1.1 is a long connection, where length refers to the duration of the connection retention. the difference between get and post:(1) Get submit, the requested data will be appended to the URL (that is, the data placed in the HTTP protocol header), to separate the URL and transmitted data, multiple parameters with & connection; Post submission, put the submitted data in the packet of the HTTP packet, That is, the data submitted by get is displayed in the Address bar, and the address bar does not change when the post is submitted. (2) Transfer data size: The HTTP protocol does not restrict the size and URL length of the transmitted data; Get commits limit URL lengths in some browsers and servers (e.g. IE has a limit of 2083 bytes for URL length), and post submissions do not pass through URL values. So theoretically there is no limit to the size of the transmitted data (no more than 64K is recommended). (3) Security: Post submission security is higher. 2. Message header  used to describe which host the client requests, and some of the client's environmental information;    Note: Not every request has the same message headerHere's a complete message header:accept:text/html,image/* [notifies the server that the client can receive content such as text, Web pages, pictures, etc.]Accept-charset:is0-8859-1 [the character encoding received by the browser is is0-8859-1]accept-encoding:gzip,compress [can accept gzip,compress compressed data]ACCEPT-LANGUAGE:EN-US,ZH-CN [Browser support Chinese, English]host:www.google.com:80 [the host to be accessed is www.google.com:80]if-modified-since:tue, Jul 18:23:51 GMT [notifies the server client of the time of the local buffer file]referer:http://www.google.com/index.html [tells the server which page this request comes from, this message header is often used to prevent hotlinking]user-agent:mozilla/4.0 (compatible:msie5.5; Windows NT 5.0) [Tell server client browser's kernel]cookies: [Cookies]connection:close/keep-alive [Stay connected, do not disconnect immediately after sending data]date:tue, Jul 18:23:51 GMT [browser sends this HTTP request time] 3, send the content  Format: Content name = Content body, multiple content use & separate     Second, HTTP response  the full HTTP response includes the status line, the multiline message header, the Reply entity content (The message header and the content are still separated by a blank line). 1, status line: used to describe the results of server processing of requests;   Format: HTTP version number status code reason description <CRLF>    such as: http/1.1 0K;where the status code is a three-bit decimal number that represents the server's processing of the request, and the response status code is divided into 5 classes: 
Status code Meaning
100~199 Indicates a successful receive request that requires the client to continue submitting the next request in order to complete the process
200~299 Indicates a successful receive request and has completed the entire process, typically 200
300~399 To complete the request, the customer needs to refine the request further. For example, the requested resource has been moved to a new address, commonly used 302, 307
400~499 The client's request has errors, commonly used 404. For example, the page visited does not exist
500~599 Server side error, common 500
2. Response message Header:  The basic information used to describe the server, and the description of the data, which the server uses to describe information that informs the client how to handle the data that is being echoed later.     Here's a complete message header:location:http://www.cnblogs.com/index.jsp [Let the browser navigate to the URL]Server:apache Tomcat [notifies the browser server that Tomcat]Content-encoding:gzip [tell the browser that the server is using gzip compression]content-length:80 [tells the browser to echo the data size to 80 bytes]CONTENT-LANGUAGE:ZH-CN [Support Chinese]content-type:text/html; charset=utf-8 [loopback content format is text/html; encoding uses utf-8]last-modified:tue, Jul 18:23:51 GMT [tells the browser that the resource last updated time]refresh:10,url=http://www.baidu.com [after 10 seconds refresh jump to http://www.baidu.com this page]content-disposition:attachment; filename = aaa.txt [tell the browser to have a file to download]transfer-encoding:chunked [encoding of transmission]set-cookie:ss=q0=5lb_nq; Path=/search [Cookie Information]Expires:-1 [tells the browser how to cache data, mainly for IE browser]Cache-control:no-cache [tells the browser how to cache data]Pragma:no-cache [tells the browser how to cache data]connection:close/keep-alive [Save connection or Close]Date:tue, 18:23:51 GMT [Echo page time] 3. Entity Content data that is echoed back to the client on behalf of the server;    third, the focus some sites on the interface real-time update requirements are very high, you need to pay attention to a detail, if just the cursor to the address bar, press ENTER to refresh, when the refreshed page has a cache will not be re-sent to the server HTTP request, there is a cache when the refresh need to click the Refresh button to refresh. How does the server make the client browser do not cache these key pages? This involves the three message headers of expires, Cache-control, and pragma in the HTTP response message header. In the development of non-cache, these three must be specified, in order to be very good compatible with a variety of browsers. such as: Response.setdateheader ("Expires",-1); indicates no cache, this method can also specify when to cache.

Analysis of Web Development--http Protocol

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.