Javascript Ajax summary --HTTP header information

Each HTTP request and response are with corresponding header information, some useful to developers, some useless. XHR object also provides a method of operating the two head (i.e., request headers and response header) information. 
By default, while transmitting XHR request, it will send the following header information.
* Accept: content type browser can handle.
* Accept-Charset: character set the browser can display.
* Accept-Encoding: browser can handle compressed code.
* Accept-Language: language browser is currently set.
* Connection: the type of connection between the browser and the server.
* Cookie: Cookie any of the current page settings.
* Host: issuing domain page where the request.
* Referer: URL issued by the requested page. (HTTP specification this field is misspelled, in order to ensure consistency with the norms, only the wrong)
* the User-Agent: browser user agent string.

Related methods:
1, setRequestHeader (): set a custom request header information
parameters:
(1) name of the header field
(2) the value of the header field
send custom header information, setRequestHeader () method on the open ( ) and send between ().
Such as:
  
xhr.setRequestHeader ( "myHeader", "MyValue");

2, the getResponseHeader (): the incoming header field names, to obtain the corresponding response headers
3, getAllResponseHeaders (): acquire the header information contains all of a long string

server, it can also be used to send additional header information, structured data to the browser.
getAllResponseHeaders (without custom information case), return:
a Date: Sun, 14 Nov 2004 18:04:03 GMT
Server: the Apache / 1.3.29 (Unix)
Vary: the Accept
the X-Powered-By-: PHP / 4.3.8
Connection: Close
the Content-the Type: text / HTML; charset = iOS-8859-1
easily check the names of all the response header field.

Guess you like

Origin www.cnblogs.com/wuxxblog/p/11111424.html