HTTP request format:
<Request-line>
<Headers>
<Blank line>
[<Request-body>]
Note: The first line must be a request line to describe the request type, resource to be accessed, and the HTTP Version Used.
Next is a header section, which describes additional information to be used by the server.
Then there is a blank line.
You can add any other data [called the body] Later.
Example 1 GET request:
Get, HTTP, 1.1
Accept :*/*
Accept-language: ZH-CN
Accept-encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; sv1;. Net CLR 2.0.50727;. Net CLR 3.0.04506.648;. Net CLR 3.5.21022)
HOST: www.google.cn
Connection: keep-alive
Description: The first part of the request indicates that the request is a GET request. the second part of the row is a slash (/), which indicates that the request is the root directory of the domain name. the last part of this row indicates that http1.1 is used (another optional version is 1.0 ).
Row 2nd is the first header of the request. Host indicates the request destination. the User-Agent can be accessed by both the server and client scripts. It is an important foundation for the browser type detection logic. this information is defined by your browser and is automatically sent in each request. connection, usually set the browser operation to keep-alive
Part 3: Empty rows. This empty row is required even if the request body does not exist.
Example 2 POST request:
Post/http1.1
HOST: www.wrox.com
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; sv1;. Net CLR 2.0.50727;. Net CLR 3.0.04506.648;. Net CLR 3.5.21022)
Content-Type: Application/X-WWW-form-urlencoded
Content-Length: 40
Connection: keep-alive
Name = Professional % 20 Ajax & publisher = Wiley
Note: Change get at the beginning of the request line to post to indicate different request types.
Content-Type describes how the content of the request body is encoded. the browser always transmits data in the format of application/X-WWW-form-urlencoded, which is a MIME type for simple URL encoding. content-Length indicates the number of bytes of the Request body.
Finally, the form of the Request body. Name-value pair.
HTTP Response format:
<Status-line>
<Headers>
<Blank line>
[<Response-body>]
Example:
HTTP/1.1 200 OK
date: Fri, 22 May 2009 06:07:21 GMT
Content-Type: text/html; charset = UTF-8
note: the HTTP Status Code 200 indicates that the resource is found and everything is normal.
date: date and time when the response is generated.
Content-Type: Specifies the MIME type of HTML (text/html), encoding type is UTF-8
HTML source style.