1. Use Telnet to test HTTP protocol in command line windowHTTP messages are made up of plain ASCII text. The message includes the message header and the data body part. Message headers in units of behavior, each line with CRLF (carriage return and newline) end, after the end of the message header, add an additional CRLF, after the content is the data body part. We can test the HTTP protocol at the Command Line window by Telnet.
1. Use Telnet to connect to the HTTP server, if you want to request the index.html page from Google, first connect to the server's 80 port telnet www.google.cn 80 2. Now connected to the server, send HTTP request message: get/index.html http/1.1 connection:close Host:www.google.cn input The above content, continuously typing two return, haha, is not see return results. This request means that the Index.html page is requested through the 1.1 version protocol, and the Connection:close is a utility short connection, that is, the server is disconnected after it returns, and the host name of the well-known page in the Host field. The return result should be this: http/1.1 OK cache-control:private, Max-age=0 Date:fri, 2009 12:26:17 GMT Expires:-1 Content-type : text/html; charset=gb2312 set-cookie:pref=id=7bbe374f53b6c6a8:nw=1:tm=1230899177:lm=1230899177:s=2eghuzjnrtdqub_a; Expires=sun, 02-jan-2011 12:26:17 GMT; path=/; domain=.google.com SERVER:GWS transfer-encoding:chunked Connection:close Here is an additional CRLF 2. Request Message FormatThe following figure is the general format of the HTTP protocol request: The first line of the request line is the request line: The Request method URL path HTTP version number, and the request line in the above example is: get/index.html http/1.1 Use the Get method to request the index.html file under the server root directory, and contract to use the http/1.1 version. The request methods include get, POST, head, OPTIONS, TRACE, put, and so on, the first 2 kinds of the most commonly used. 1. Get method. The parameter is submitted by appending the parameter to the URL. such as http://www.google.cn/search?hl=zh-CN&newwindow=1&rls=com.microsoft%3Azh-cn%3AIE-SearchBox&q=%E6% 89%8b%e6%9c%ba&meta=&aq=f&oq= get 2. Post method. Submit parameters by attaching parameters to the requested header line (get mode is no data body). Get-mode submission parameter data volume is generally limited to 1k, and post is unrestricted. Post is typically used when the form data is submitted. 3. The head method does not allow the server to return any entities in response. For the response part of the head request, its HTTP header contains the same meta information as the GET request. By using this method, you can get the meta information of the resource specified by the request URI without having to transfer the entire entity body. This method is commonly used to test the legality, accessibility, and recent updates of hyperlinks. The contents of the head line header line are generally used to describe the types that the client can be compatible with. If Accept-language tells the server what languages the client supports, Cache-control tells the server whether the client supports Cache. The Subsidiary body (data entity) requested, get is not applicable, when the Post method submits the data, to hold the requested parameter. Client pass parameter Mode 1. Get method passed directly behind the URL. 2. Post mode delivery, the request line tells the server parameter length, transmitted independently to the server through the Subsidiary body. 3. Cookie way to pass, do not forget this way, session sessions is the function of this way to achieve OH. Some common header row request parametersuser-agent: Browser information for the client.Connection: Close indicates that a short connection is used, and keep-alive indicates that the client supports persistent connections.Date: The current time that the message was generated.Accept-language: The language supported by the client.Cache-controL: Whether the client supports cache. No-cache indicates that the client does not support cache, such as max-age=3600, to tell the user Agent how long the response result of the request is valid, within the validity period, when the user again needs access, directly from the client local extraction, do not need access to the server.Referer: Referer is used to tell the server which URL the request originated from, and it can be used to track the user's Web Access path.if-modified-since: If the request message contains the If-modified-since header field, the syntax of the Get method becomes the "condition got", i.e. "(conditional get)." The conditional get method can determine the specified resource, and if it has been updated after the specified date in the If-modified-since header field, the transmission will not start, otherwise it will not be transmitted. This condition get allows the cached entity to be refreshed without having to go through multiple requests or unnecessary data transfers, thereby helping to reduce network load.last-modified: Sun, Dec 2008 23:52:56 GMTETag: "1cbf3-dfd-3a2adcd8″ general application in the file download, to identify the response content of the last modification time or content than the code, the next time the user agent needs, the service first to determine whether the two values are consistent with the server, the same does not need to return content.Expires: The response of the request expires at what time, and the agent can return the previous response results directly from the cache before it is invalidated.Host: Specifies the host and port number on which the resource is requested. The http/1.1 request must specify host or the server will return a 400 status code. Request message Example GET request example: Get/css/news070130.css http/1.1 Accept: */* referer:http://news.qq.com/a/20081224/000088.htm ACCEPT-LANGUAGE:ZH-CN Accept-encoding:gzip, deflate If-modified-since:thu, Mar 2007 02:05:43 GMT; length=11339 user-agent:mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1. NET CLR 1.1.4322;. NET CLR 2.0.50727) Host:news.qq.com connection:keep-alive cookie:ssid=idlsesels; flv=9.0; ICACHE=ADLFMBGC; Adid=adsdifids; isflucky_50829637=0; POST Request Example: post/login.php http/1.1 accept:image/gif,*/* accept-language:zh-cn accept-encodeing:gzip user-agent:msie6. 0 Host:www.some.com connection:keep-alive content-length:7 cache-control:no-cache cookie:name1=value1; Name2=value2; Here's an extra CRLF Username=b&passwd=d.3. Response Message FormatThe response message includes a status line, several header rows, and a subordinate body (an HTML data entity). Status line status line includes: HTTP protocol version number, status code, status code text description information. For example: http/1.1 OK status code consists of a three-digit number, the status code has 5 meanings: 1. 1xx. Information, request received, continue processing. 2.2xx. Success. 200 request succeeded; 206 Breakpoint continued. 3.3xx. redirect. General jumps to the new address. 4.4xx. Client error. 404 files do not exist 5. 5xx. Server error. 500 internal error. Head LineSet-cookie: The server sets the client cookie. Formatting is name=value, separated by semicolons when setting multiple parameters. Set-cookie will also use a few parameters: path set a valid path, domain set the name of the cookie in effect, expire set the valid time of the cookie, 0 means that the browser is closed to expire.Location: This parameter implements redirection when the server returns a 3xx redirect. Ads link to the jump on the use of this Protocol.Content-length: The length of the Subsidiary body (data entity)