Request and Response formats

Source: Internet
Author: User

Web-011 (Request and Response formats)

The format of an HTTP Request is usually as follows:
GET/path/maid HTTP/1.1
Host: localhost
User-agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1;. net clr 1.1.4322 );
Connection: keep-Alive
Other header information...
(Empty rows)
Request Body

The first line is the request type (method), requested resource (without the domain name path), and HTTP Version. Host is the requested Host address, which is the first header information. It, together with the resources requested in the first line, forms the complete request path, that is, the complete request URL. The header information is followed by an empty line, followed by the request Body.
If it is a GET request, the Body is empty, and the data sent is in the GET part. As a Query String, it becomes part of the request resource, for example: Get/path/Servlet1 /? Name = John % 20 Smith & age = 30http/1.1
For a POST request, the data is in the Body part. For example, the Body part contains: name = John % 20 Smith & age = 30.
For the post request, it has two headers, Content-Type and Content-Length.
Content-Type indicates the encoding Type of the data in the Body. Content-Length indicates the Length of the Body.
/*************************************** ***************************/
The format of an HTTP Response is usually as follows:
HTTP/1.1 200 OK
Date: Sat, 31 Dec 2005 23:59:59 GMT
Content-Type: text/html; charset = ISO-8859-1
Content-Length: 122
Other header information...
(Empty rows)
Response Body

The first line is the status line, which is the HTTP Version, number indicating the status, and information (200 and OK ). the following is some header information. For example, Date is the time when Response is generated, Content-Type and Content-Length indicate the encoding Type and Length of the Body Content, and the meaning is the same as that of the Request. After the header information ends, a blank line is followed by the Body to store the data returned to the user. In the previous example, the data may be text, HTML, or XML.
**********************/
The GET header information is basically included in the POST header information, so the following is only for the Post header information.
The header information is also a Name/Value pair. The following is the POST header information, and the equal sign is added during programming, not part of the header information format:
1. accept = */*: indicates the MIME type that the browser can process. Common types include text/html (HTML document) and text/xml (XML document.
2. accept-language = en-ca: Set language.
3. who = Me: User-defined.
4. referer = http: // localhost: 8080/HelloServlet/postRequestInfo.html: Call the Servlet URL, that is, click a webpage to the second webpage, the first webpage is called the referer of the second webpage.
5. cache-control = no-cache: whether to use the buffer. By default, the buffer is used.
6. content-type = application/x-www-form-urlencoded: content type.
7. if-modified-since = Thu, 06 Apr 2006 01:00:00 GMT: after this date, if the webpage changes, refresh it, which is also a method to prevent webpage buffering.
8. accept-encoding = gzip, deflate) content-Encoding.
9. user-agent = Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1;. net clr 1.1.4322): browser that sends the Request. This result is generated by IE browser, but is still displayed as Mozilla of NetScape. Only the MSIE in the brackets is the actual browser type.
10. host = localhost: 8080: Very simple, that is, the host address.
11. content-length = 1: the length of the Request content.
12. connection = Keep-Alive: whether the browser can process continuous HTTP connections. Persistent connection means that the browser can access multiple files, such as an HTML file and image files on the file. The meaning of Keep-Alive is continuous connection.

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.