Explanation of header information in HTTP messages
This article follows: The HTTP message includes the client's request message to the server and the server's response message to the client. These two types of messages consist of a starting line, one or more header fields, a blank line that is just the end of the head field, and an optional message body. The header fields of HTTP include the general header, the request header, the response header, and the four parts of the entity header. Each header field consists of a domain name, a colon (:), and a domain value of three partsheader information for HTTP request
1. HTTP request Mode
As the following table:
GET |
Request a file from a Web server |
POST |
Send data to the Web server for processing by the Web server |
PUT |
Send data to the Web server and store it inside the Web server |
HEAD |
Checks if an object exists |
DELETE |
Delete a file from the Web server |
CONNECT |
Providing support for channels |
TRACE |
Trace the path to the server |
OPTIONS |
Querying the performance of a Web server |
Description:
Mainly used to "get" and "POST".
Example:
POST/TEST/TUPIAN/CM http/1.1
into three parts:
(1) Post:http request method
(2)/TEST/TUPIAN/CM: Request the Directory address (or directive) of the Web server
(3) Http/1.1:uri (Uniform Resource Identifier, Uniform Resource Identifier) and its version
remark:
In Ajax, the corresponding method property is set.
2. Host
Description
The requested Web server domain name address
3, User-agent
Description
Details of the browser type that the HTTP client is running. With this header information, the Web server can determine the client browser category to the current HTTP request.
Instance:
user-agent:mozilla/5.0 (Windows; U Windows NT 5.1; ZH-CN; rv:1.8.1.11) gecko/20071127 firefox/2.0.0.11
4. Accept
Description
Specifies the types of content that clients can receive, and the order in which they are received in the content type indicates the order in which clients receive them.
For example:
accept:text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
remark:
In the AJAX Code encapsulation of Prototyp (1.5), the accept default is set to "Text/javascript, text/html, Application/xml, Text/xml, */*". This is because Ajax obtains the JSON data pattern returned by the server by default.
In AJAX code, you can use the setRequestHeader function method in the XMLHttpRequest object to dynamically set these header information.
5, Accept-language
Description
Specifies the preferred language for the HTTP client browser to display the return information.
Instance:
accept-language:zh-cn,zh;q=0.5
This defaults to Chinese.
6, Accept-encoding
Description
Specifies that the Web server that the client browser can support returns the content compression encoding type. Indicates that the server is allowed to compress the output before it is sent to the client to conserve bandwidth. The return compression format that the client browser can support is set here.
Instance:
Accept-encoding:gzip,deflate
Note:
In fact, in many of Baidu's product lines, Apache compresses the data in gzip format before returning the page data to the client.
7, Accept-charset
Description
The set of character encodings that the browser can accept.
Instance:
accept-charset:gb2312,utf-8;q=0.7,*;q=0.7
8, Content-type
Description
Displays the content type submitted by this HTTP request. This property is typically only required for post submission.
Instance:
Content-type:application/x-www-form-urlencoded;charset:utf-8
There are two types of encoding available for the Content-type property values:
(1) "application/x-www-form-urlencoded": the type of encoding used when the form data is submitted to the server, the default value is "application/x-www-form-urlencoded". However, this encoding is inefficient when sending large amounts of text to the server, including text or binary data that contains non-ASCII characters.
(2) "Multipart/form-data": When the file is uploaded, the type of encoding used should be "Multipart/form-data", which can both send text data and support binary data upload.
You can use "application/x-www-form-urlencoded" when committing to data alone, and when you commit a file, you need to use the "multipart/form-data" encoding type.
The charset character encoding of the commit content is also specified in the Content-type property. Typically not set, it simply tells the Web server what character encoding to use for the data submitted by the post.
Generally in the development process, the front end works with the backend UI engineer to discuss what character encoding format to use for post submission, and then the backend UI engineer to parse the submitted data according to a fixed character encoding. So the charset set here does not have much effect.
9, Connection
Description
Indicates whether a persistent connection is required. If the Web server side sees the value here as "keep-alive", or sees the request using an HTTP 1.1 (HTTP 1.1 By default for persistent connection), it can take advantage of the persistent connection, when the page contains multiple elements (such as applets, pictures), Significantly reduce the time it takes to download. To do this, the Web server needs to send a content-length (the length of the message body) header back to the client HTTP header, and the simplest implementation is to write the content to Bytearrayoutputstream first, and then Calculates the size of the content before it is formally written.
Instance:
connection:keep-alive
10, Keep-alive
Description
Displays the keep-alive time for this HTTP connection. The client-to-server connection continues to be valid, and the Keep-alive feature avoids establishing or re-establishing a connection when a subsequent request to the server occurs.
The previous HTTP request is a one-stop connection, and after the http/1.1 protocol, there is a long connection, that is, the connection is not broken within the specified keep-alive time.
Instance:
keep-alive:300
11. Cookies
Description
When an HTTP request is sent, all cookie values stored under that request domain are sent to the Web server.
12, Referer
Description
contains a URL where the user accesses the currently requested page from the page represented by the URL Responses Part
Header |
explain |
Example |
Accept-ranges |
Indicates whether the server supports the specified range request and what kind of staging request |
Accept-ranges:bytes |
Age |
Estimated time (in seconds, non-negative) from the original server to the proxy cache |
Age:12 |
Allow |
A valid request behavior for a network resource is not allowed to return 405 |
Allow:get, HEAD |
Cache-control |
Tell if all caching mechanisms can be cached and which type |
Cache-control:no-cache |
Content-encoding |
The type of return content compression encoding supported by the Web server. |
Content-encoding:gzip |
Content-language |
The language of the response body |
Content-language:en,zh |
Content-length |
The length of the response body |
content-length:348 |
Content-location |
Alternate alternative address to request resource substitution |
Content-location:/index.htm |
Content-md5 |
Returns the MD5 checksum value of a resource |
content-md5:q2hly2sgsw50zwdyaxr5iq== |
Content-range |
The byte position of this section in the entire return body |
Content-range:bytes 21010-47021/47022 |
Content-type |
Returns the MIME type of the content |
content-type:text/html; Charset=utf-8 |
Date |
Time the original server message was issued |
Date:tue, 08:12:31 GMT |
ETag |
The current value of the entity label of the request variable |
ETag: "737060cd8c284d8af7ad3082f209582d" |
Expires |
Date and time when the response expires |
Expires:thu, 16:00:00 GMT |
Last-modified |
Requested last modified time for resource |
Last-modified:tue, 12:45:26 GMT |
Location |
Used to redirect the receiver to the location of the non-request URL to complete the request or identify the new resource |
Location:http://www.zcmhi.com/archives/94.html |
Pragma |
Includes implementing a specific instruction that can be applied to any receiver on the response chain |
Pragma:no-cache |
Proxy-authenticate |
It indicates the authentication scheme and the parameters on the URL that can be applied to the proxy |
Proxy-authenticate:basic |
Refresh |
Applied to redirect or a new resource was created, redirected after 5 seconds (proposed by Netscape, supported by most browsers) |
Refresh:5; Url= http://www.zcmhi.com/archives/94.html |
Retry-after |
Notifies the client to try again after a specified time if the entity is temporarily undesirable |
retry-after:120 |
Server |
Web Server Software Name |
server:apache/1.3.27 (Unix) (Red-hat/linux) |
Set-cookie |
Set HTTP Cookies |
Set-cookie:userid=johndoe; max-age=3600; Version=1 |
Trailer |
Indicates that the header domain is present at the end of the chunked transfer code |
Trailer:max-forwards |
Transfer-encoding |
File transfer encoding |
Transfer-encoding:chunked |
Vary |
Tells the downstream agent whether to use the cache response or request from the original server |
Vary: * |
Via |
Tells the proxy client where the response was sent by |
via:1.0 Fred, 1.1 nowhere.com (apache/1.1) |
Warning |
Warning about possible issues with the entity |
warning:199 Miscellaneous Warning |
Www-authenticate |
Indicates the authorization scheme that the client request entity should use |
Www-authenticate:basic |
second, the header of the setting method
Xhr.setresponseheader ("Content-type", "application/x-www-form-urlencoded");//Set Request header
PHP gets the post parameters in several ways
1, $_post[' paramname '] can only receive data submitted by content-type:application/x-www-form-urlencoded
2, file_get_contents ("Php://input") for most types of content-type
Php://input allows the raw data to be read from the POST. Compared to $HTTP _raw_post_data, it brings less pressure to memory and does not require any special php.ini settings. Php://input cannot be used for enctype= "Multipart/form-data".
3, globals[' http_raw_post_data ']; always produce globals[' Http_raw_post_data ']; always produces globals[' Http_raw_post_data ']; Always produce http_raw_post_data variables containing the original POST data. This variable is only generated when it encounters data that does not recognize the MIME type. $HTTP _raw_post_data is not available for enctype= ' multipart/form-data ' form data.
If the POST data is not recognized by PHP, you can use $GLOBALS [' Http_raw_post_data '] to receive it, such as text/xml or soap, and so on.